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 Incognito40 · Aug 15, 2014 at 08:39 AM · restartgameover

How do I give an option to retry a level or return to a level selection menu opposed to just restarting the level?

I would like to give an option to either retry or go to main menu. I am brand new to coding and unity so simple basic explanations would be greatly appreciated. I would assume a "waitForSeconds" would be needed before the option appears, however I do not know how to implement that in my current scrip and this is why I have implemented application.LoadLevel(Application.loadedLevel);. instead. As you will notice the first two public game objects are not put into use simply because Im unsure how at this time. Here is the script that I have for now. Please do not be rude. I have hesitated to ask this question for the last 2 days simply because I don't want someone to make a newbie feel like an idiot.

using UnityEngine; using System.Collections;

public class TimeText : MonoBehaviour { public GameObject gameOverText; public GameObject restartButton; public GUIText timeText; public float timer = 30.00F;

 // Update is called once per frame
 void Update () 
 {
             timer -= Time.deltaTime;
     
             timeText.text = "Remaining Time " + timer.ToString ("0.00");
     
             if (timer <= 0) {
                     timeText.text = " Score";
                     Time.timeScale = 0;
         Application.LoadLevel(Application.loadedLevel);

     }
 }

}

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 zaid87 · Aug 15, 2014 at 09:37 AM

Well, I'm kinda newbie to Unity too, so hi fella.

Anyway, I would suggest you create a state system for controlling your game's state. When inside the "game over" state, you display the buttons for restarting the level or going back to main menu. I think it would also be better to make a different Scene for the main menu, this way you can use the Application.LoadLevel() to load between main menu and in-game. For example :

 enum GAMESTATE {PLAYING=0, GAMEOVER};
 
 function Start() {
    GAMESTATE currentState = GAMESTATE.PLAYING;
 }
 function OnGUI() {
 
    if (currentState == GAMESTATE.GAMEOVER){
       if (GUI.Button(new Rect(0, 0, 50, 20), "Retry")) {
          Application.LoadLevel(Application.loadedLevel); // restart the level
       }
 
       if (GUI.Button(new Rect(0, 0, 50, 20), "Exit")) {
          Application.LoadLevel(0); // go back to main menu
       }
    }
 }

The LoadLevel(0) is assuming the index of main menu's scene is 0, you can set this in the Build Settings. Hopefully this can help you a bit.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Restart level dialog as a prefab problems? 0 Answers

How do I make Game Over text stay enabled for a few seconds before the Application Load function runs? 1 Answer

Display Time At Game Over Scene 1 Answer

Delete Instance. 1 Answer

Scripts won't compile unless I restart Unity 3 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