• 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 RNVitter · Jun 11, 2014 at 01:42 PM · waitforsecondsgameover

On death show onGUI and wait 5 seconds to load next level

When the player gets destroyed I want to show a Game Over OnGUI and wait for 5 seconds to load the next scene (restart/quit/addscore scene).

 void OnDestroy() 
 { 
     Application.LoadLevel(Application.loadedLevel + 1); 
 } 
Comment
Add comment · Show 2
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 roojerry · Jun 11, 2014 at 01:44 PM 3
Share

What did you try? There is OnGUI documentation and Coroutine documentation with examples

avatar image ffxz7ff · Jun 11, 2014 at 02:33 PM 0
Share

And what is your question?

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by HarshadK · Jun 11, 2014 at 01:44 PM

All you need is a coroutine.

 bool showGUI = false;

 void OnDestroy() 
 { 
     StartCoroutine("LoadNextLevel"); 
 } 

 void OnGUI() {
     if(showGUI) {
         // Show the content of Game Over GUI
     } else {
         // Hide the Game Over GUI
     }
 }
 
 IEnumerator LoadNextLevel() {
     showGUI = true;
     yield return new WaitForSeconds(5);
     showGUI = false;
     Application.LoadLevel(Application.loadedLevel + 1);
 }
Comment
Add comment · Show 9 · 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 RNVitter · Jun 11, 2014 at 02:07 PM 0
Share

this is my code now...

 bool showGUI = false; 
 
 public GUIStyle Font; 
 
 
 
     void OnDestroy() 
     {  
         StartCoroutine("LoadNextLevel");
         //Application.LoadLevel(Application.loadedLevel + 1); 
     } 
 
     void OnGUI() {
         if(showGUI) {
             GUI.TextArea (new Rect(330,430,100,30), "g a m e  o v e r", Font); 
         } else {
             GUI.TextArea (new Rect(330,430,100, 30), "");
         }
     }
     
     IEnumerator LoadNextLevel() {
         showGUI = true;
         yield return new WaitForSeconds(5);
         showGUI = false;
         Application.LoadLevel(Application.loadedLevel + 1);
     }

it saws that IEnumerator does not exist in the current context

avatar image HarshadK · Jun 11, 2014 at 02:13 PM 0
Share

There is no error in the code since when I tried your code snippet it is not throwing any error. Just copy and paste the code again in the file and try it.

avatar image RNVitter · Jun 11, 2014 at 02:21 PM 0
Share

its fixed now but now so there are no areas but it does not show when my player dies. any ideaswhy?

avatar image HarshadK · Jun 11, 2014 at 02:22 PM 0
Share

What does it not show? Can you be more specific?

avatar image RNVitter · Jun 11, 2014 at 02:27 PM 0
Share

the GUI never shows on the screen, and the next level is never loaded

Show more comments
avatar image
0

Answer by Andres-Fernandez · Jun 11, 2014 at 02:30 PM

You can use Invoke.

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.

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

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

Related Questions

Wait a second before enemy move 1 Answer

yield return waitforseconds not waiting? 3 Answers

how do i do somting, wait and then do somthing else 1 Answer

Coroutine wait is not working 1 Answer

Assign a clip to an AudioSource when it finishes playing. 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