• 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 Dogg · May 22, 2014 at 09:57 PM · gameover

Game Over Screen Won't Work

So I was adding a Quit Button to my Main Menu Scene, and after I added the button(I still have to actually make it quit) everything got screwed up. I played the game but my colliders were not working, then I noticed I had the main menu scene set to an old scene that I had, so I changed it to my newest scene and set it to the build settings. The problem was fixed, but now my Game Over Screen wont pop up after I die. It just restarts the game to the main menu, I re added the Game Over Scene to the build settings, but now it just restarts the game from the start and I play it over and over again. When I open the Game Over Scene by itself and press restart, it does nothing. I would leave it like this but now nobody will know what their score was, so please help.

UPDATE: I have two GameOver Scenes in the build settings. There both the same scenes but ones on top of the Main Menu Scene, and one is below the Game scene. When I uncheck the one below the Game Scene and check the top one, the game restarts right away after I die. When I do the opposite, it takes me to the Main Menu Screen after I die. I think it has to do with the placing of the scenes in the build.

 public class GameOverScript : MonoBehaviour {
 
     int score = 0;
 
     void Start () {
         score = PlayerPrefs.GetInt("Score");
     }
 
     void OnGUI()
     {
         GUI.Label (new Rect (Screen.width / 2 - 40, 50, 80, 30), "GAME OVER");
 
         GUI.Label (new Rect (Screen.width / 2 - 40, 300, 80, 30), "Score: " + score);
         if(GUI.Button(new Rect(Screen.width    / 2 - 30, 350, 60, 30), "Retry?"))
         {
             Application.LoadLevel(0);
         }
     }
 
 }

 public class MainMenu : MonoBehaviour {
 
     public Texture backgroundTexture;
 
     public float guiPlacementY1;
     public float guiPlacementY2;
     public float guiPlacementY3;
 
     public float guiPlacementX1;
     public float guiPlacementX2;
     public float guiPlacementX3;
 
     public bool Options;
 
 
     void OnGUI(){
         // Display our background texture
         GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),backgroundTexture);
 
 
         // Display our Buttons
         if (GUI.Button (new Rect (Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .5f, Screen.height * .1f), "Play Game")) {
             print ("Ckicked Play Game"); Application.LoadLevel("23.6 Scene");
 
         }
         if (GUI.Button (new Rect (Screen.width * guiPlacementX2, Screen.height * guiPlacementY2, Screen.width * .5f, Screen.height * .1f), "Options")) {
             print("Clicked Play Game"); Options = true;
         }
         
         if (Options) {
             
             //do something when we're viewing options
 
         }
         if (GUI.Button (new Rect (Screen.width * guiPlacementX3, Screen.height * guiPlacementY3, Screen.width * .5f, Screen.height * .1f), "Quit")) {
             print("Clicked Play Game");
 
         
 
         }
     }
   }
 
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
Best Answer

Answer by tanoshimi · May 22, 2014 at 10:22 PM

"I think it has to do with the placing of the scenes in the build." - yes, because you're calling Application.LoadLevel(0), which will always load the first level listed in your build settings. Did you read the manual?

http://docs.unity3d.com/Documentation/ScriptReference/Application.LoadLevel.html

Comment
Add comment · Show 1 · 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 Dogg · May 22, 2014 at 10:46 PM 0
Share

I already fixed it. Thanks for the link though. No I did not read the manual, I will read it though since by your answer it seems it's useful.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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 avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Player lives script help 1 Answer

Animation spins wildly after completed 0 Answers

hide object start script 4 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