Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by mradebe_eti · Sep 20, 2013 at 12:42 AM · c#levelpointscomplete

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DannyB · Sep 20, 2013 at 08:30 AM 0
Share

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 )

avatar image mattssonon · Sep 20, 2013 at 09:44 AM 1
Share

Your code is ridiculous. Indent it properly and stop using if () without curly brackets.

avatar image mradebe_eti · Sep 20, 2013 at 04:43 PM 0
Share

Thanks DannyB. I'm new to Unity and coding, so I appreciate the advice.

avatar image DannyB · Sep 20, 2013 at 04:45 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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;
         }
     }
 }  
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JamieSinn · Sep 20, 2013 at 05:13 PM 0
Share

This is a possible fix, just a reference for anyone else, i might try to fix it soon too.

avatar image mradebe_eti · Sep 20, 2013 at 05:16 PM 0
Share

Thanks for the advice and I appreciate you showing me how to indent my code.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges