Search Unity

URGENT: Help Needed (Ignoring IF statements)

Discussion in 'Scripting' started by mojokage, May 29, 2015.

  1. mojokage

    mojokage

    Joined:
    Feb 15, 2014
    Posts:
    8
    Okay so I'm working on a leaderboard system that stays active as long as the exe is running. The high score is calculated by this script:

    startTime = Time.time;
    startTime = Time.timeSinceLevelLoad;


    and then I make startTime = newScore in another script. This then passes over to the script below. The problem is that it is ignoring any if statements. Every time I get any score, that becomes the value of scoreNo1, scoreNo2 AND scoreNo3 (regardless of whether it's higher or lower than the previous) and the next time I run through (in the same debug session) it overwrites it. Please assist if you can! At first I thought the error could be with the RED text above but when I fixing startTime to be 10 I got the same error, everything was equal to 10. I'd really appreciate any help. Below is the code for the leaderboard:

    Code (JavaScript):
    1. var scoreNo1 : int =0;
    2. var scoreNo2 : int =0;
    3. var scoreNo3 : int =0;
    4.  
    5. function Update () {
    6. if (deathMover.newScore >= scoreNo1){
    7. scoreNo3 = scoreNo2;
    8. scoreNo2 = scoreNo1;
    9. scoreNo1 = deathMover.newScore;
    10. } else {
    11.  
    12. if (deathMover.newScore >= scoreNo2){
    13. scoreNo3 = scoreNo2;
    14. scoreNo2 = deathMover.newScore;
    15. } else {
    16.  
    17. if (deathMover.newScore >= scoreNo3){
    18. scoreNo3 = deathMover.newScore;
    19. }
    20. }
    21. }
    22. }
     
    Last edited: May 29, 2015
  2. mojokage

    mojokage

    Joined:
    Feb 15, 2014
    Posts:
    8
    Okay the first problem was that it was in the Update function so it was being continuously called