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
0
Question by mradebe_eti · Aug 28, 2013 at 12:59 AM · c#levelcomplete

Complete Level Script

Hi,

I'm trying to see where I am going wrong with my script once a player completes the level. I need to have the screen to say "Try Again!" and the player lose a life if they score below 1500 points. I also need the screen to say "Level Cleared!" if the player score above 1500 points. Here is my script:

public class PlayerResults : MonoBehaviour { public bool Result1 = false; public bool Result2 = false;

 void OnLevelWasLoaded(int level) {
     
    if (level == 8)
 
     if (Score.score < 1500) {

                 Result1 = true;
                 Lives.curLives--;
 } 
     if (Score.score > 1500) {

                 Result2 = true;
     
     }
     
 }    
     void ResultText(bool Result1, bool Result2) {
     
          if (Result1 = true)

             {
                 guiText.text = "TRY AGAIN!";
                 guiText.material.color = Color.black;
             }
         
             if (Result2 = true)
 
             {
                 guiText.text = "LEVEL CLEARED!";
                 guiText.material.color = Color.black;
     }
 }

}

Thanks.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Azmodii · Aug 28, 2013 at 08:39 AM

You need to add this line;

 ResultText ( Result1, Result2);

Add it like so;

 void OnLevelWasLoaded(int level) {
  
    if (level == 8)
  
     if (Score.score < 1500) {
  
                 Result1 = true;
           Lives.curLives--;
 } 
     if (Score.score > 1500) {
  
                 Result2 = true;
  
     }
 
     ResultText ( Result1, Result2);
  
 }  

As far as I can see, you werent actually "calling" the function.

It would also be a lot clearer to use only one Bool here.

IsScoreEnough.

If its false, it will say try again, if its true, it will say level cleared. You can get rid of two if statements then.

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 mradebe_eti · Aug 28, 2013 at 05:56 PM 0
Share

So I made adjustments like you suggested, but it seems to be calling the function before I need it. The level cleared text shows before the OnLevelWasLoaded level, but I checked and I selected the correct level to show the text.

Here is my code:

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)
 
         {
             guiText.text = "LEVEL CLEARED!";
       guiText.material.color = Color.black;
 }

} }

avatar image mradebe_eti · Oct 10, 2013 at 08:47 PM 0
Share

I made a few changes to my level complete code, but it has 2 issues:

Firstly it does not show the "S$$anonymous$$ILL CLEARED!" text anymore and the second issue is that my TimerSpentText does not appear either. I'm not sure what is wrong.

 public class PlayerResults1 : $$anonymous$$onoBehaviour {
 
     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 && Score.score < 3000)    
             Application.LoadLevel("Bronze1");
             
         else if (Score.score > 3000 && Score.score < 4500)
             Application.LoadLevel("Silver1");
  
         else if (Score.score > 4500)
                 Application.LoadLevel("Gold1");
             {
                 guiText.text = "S$$anonymous$$ILL CLEARED!";
                 guiText.material.color = Color.black;
                 GameObject.Find ("TimeSpentText").guiText.text = " " + Skill1Timer.finishTime.ToString();
                    guiText.material.color = Color.black;
             }
         }
     }
 }

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

16 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

Related Questions

Help with different medals for completing a level 1 Answer

Multiple Cars not working 1 Answer

Creating a level from a textfile 0 Answers

Distribute terrain in zones 3 Answers

Disabling a script in c# not working for some reason 1 Answer


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