- Home /
Help with different medals for completing a level
Hi,
I'm pretty new to Unity and I need help with getting my script to award a player different medals based on how many points they scored in the level. The badges and the "Skill Cleared!" message are currently not appearing. What am I doing wrong?
Here is my script:
public class PlayerResults1 : MonoBehaviour { public bool IsScoreEnough = false;
     void OnLevelWasLoaded(int level) {
         if (level == 8)
             if (Score.score < 1500) {
 
                 IsScoreEnough = false;
                   Lives.curLives--;
         } if (Score.score > 1500) {
             IsScoreEnough = true;
 
     }
 
      ResultText (IsScoreEnough);
 }
     void ResultText(bool IsScoreEnough) {
         if (IsScoreEnough == false)
 
     {
             guiText.text = "TRY AGAIN!";
               guiText.material.color = Color.black;
     }
 
     else if (IsScoreEnough == true) 
         if (Score.score > 1500) {
       Application.LoadLevel("Bronze1");
    }
    else if (Score.score > 3000){
       Application.LoadLevel("Silver1");
    }
    else if (Score.score > 4500){
       Application.LoadLevel("Gold1");
 
     {
             guiText.text = "SKILL CLEARED!";
               guiText.material.color = Color.black;
     }
 }    
} }
Any assistance is appreciated.
Thanks. 
Your indentation is terrible, which makes it harder for you to realize where the problem is. Organize your indentation and put your curly braces in a consistent manner, and you will probably see the problem right away.
Hint: Look at lines 26 and 36.
Also, you don't have to ask if( IsScoreEnough == true ) you can do if( IsScoreEnough ) 
Your code is ridiculous. Indent it properly and stop using if () without curly brackets. 
Thanks DannyB. I'm new to Unity and coding, so I appreciate the advice.
Sure, and don't worry it gets easier and much more fun once you understand how to "talk" to it :) - $$anonymous$$ost of us here have been in your situation.
Answer by JamieSinn · Sep 20, 2013 at 05:07 PM
You really need to learn how to use indenting, this code is a complete mess for anyone to try and read, here is the proper intenting and formatting. And as people have said before, you can use if(bool) rather than if(bool == true) and the same goes for false, use if(!bool). Another little tip, one line if statments, if you only have one line, dont use {} just put the one code line below it. For anyone who wants to look deeper into the code, I have cleaned it up a bit
 void OnLevelWasLoaded(int level) 
 {
     if (level == 8)
     {
          if (Score.score < 1500) 
          {
              IsScoreEnough = false;
              Lives.curLives--;
          }
          if (Score.score > 1500) 
             IsScoreEnough = true;
     }
     ResultText(IsScoreEnough);
 }
 void ResultText(bool IsScoreEnough)
 {
     if (!IsScoreEnough)
     {
          guiText.text = "TRY AGAIN!";
          guiText.material.color = Color.black;
     }
     else if (IsScoreEnough) 
     {
         if (Score.score > 1500)     
             Application.LoadLevel("Bronze1");
     
         else if (Score.score > 3000)
             Application.LoadLevel("Silver1");
 
         else if (Score.score > 4500)
         {
             Application.LoadLevel("Gold1");
             guiText.text = "SKILL CLEARED!";
             guiText.material.color = Color.black;
         }
     }
 }  
This is a possible fix, just a reference for anyone else, i might try to fix it soon too.
Thanks for the advice and I appreciate you showing me how to indent my code.
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Complete Level Script 1 Answer
Please Help Me 1 Answer
open door to next level, after 10000 points were added to your score (solved) 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                