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 Nick 1 · Jul 13, 2010 at 08:07 AM · timercountdownrestart

How to restart a level with countdown?

i'm usinga countdown timer script, which keeps going on and on and on... how to restart the level if the time is over? (0:00)

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

4 Replies

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

Answer by TaigaStudios · Jul 13, 2010 at 08:30 AM

Use:

 Application.LoadLevel(1); //where 1 is the number of the level in build settings.

Comment
Add comment · Show 6 · 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 qJake · Jul 13, 2010 at 08:34 AM 3
Share

Why hard-code the level number when you have Application.loadedLevel which returns the currently loaded level?

avatar image Nick 1 · Jul 13, 2010 at 08:55 AM 0
Share

THAN$$anonymous$$S :) now i need to work out a splash screen loader before the level restarts :)

avatar image qJake · Jul 13, 2010 at 09:06 AM 0
Share

Oh sure, accept the answer with the worse program$$anonymous$$g solution... (what is this world co$$anonymous$$g to...)

avatar image Cyclops · Jul 13, 2010 at 05:45 PM 0
Share

"Fire and brimstone co$$anonymous$$g down from the skies! Rivers and seas boiling! Forty years of darkness! Earthquakes, volcanoes... The dead rising from the grave! Human sacrifice, dogs and cats living together... mass hysteria!" - Or was that a rhetorical question, @SpikeX?

avatar image TaigaStudios · Jul 14, 2010 at 03:02 PM 0
Share

@Cyclops Good one, secondly SpikeX's answer was better than $$anonymous$$e, which was copied in haste, without giving it much tought. We should always try to avoid hard-coding things when possible, but is it end of the world even though we didn't? Also SpikeX gave short explonation and I didn't votes up

Show more comments
avatar image
6

Answer by qJake · Jul 13, 2010 at 08:34 AM

When the timer reaches zero (I'm assuming you have that set up already), simply do this:

Application.LoadLevel(Application.loadedLevel);

That will "restart" the current scene (excluding any persistent game objects which have DontDestroyOnLoad set on them).

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

Answer by Chris 4 · May 02, 2011 at 07:40 PM

Try adding this to your script:

    if (restSeconds == 0)
{
Application.LoadLevel(loadedLevel);
}

Make sure you make a variable to tell unity what the loaded level is. ex:

    var loadedLevel : int;
loadedLevel = 4;
//for example 4

I hope this helps! :)

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

Answer by RickHurd · May 04, 2013 at 11:40 PM

This is what I'm using for my game, and it works just fine.

 private var startTime;
 private var restSeconds : int;
 private var roundedRestSeconds : int;
 private var displaySeconds : int;
 private var displayMinutes : int;
  
 var countDownSeconds : int;
  
 function Awake() {
     startTime = Time.time;
 }
  
 function OnGUI () {
     //make sure that your time is based on when this script was first called
     //instead of when your game started
     var guiTime = Time.time - startTime;
  
     restSeconds = countDownSeconds - (guiTime);
  
     //display messages or whatever here -->do stuff based on your timer
     if (restSeconds == 60) {
         print ("One Minute Left");
     }
     if (restSeconds == 0) {
         Application.LoadLevel("What ever you're scene is called");
         
     }
  
     //display the timer
     roundedRestSeconds = Mathf.CeilToInt(restSeconds);
     displaySeconds = roundedRestSeconds % 60;
     displayMinutes = roundedRestSeconds / 60; 
  
     text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds); 
     GUI.Label (Rect (400, 25, 100, 30), text);
 }
 
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

1 Person is following this question.

avatar image

Related Questions

How do i restart my game if countdown timer runs out on a scene 3 Answers

Need help figuring how to add more time to timer 1 Answer

Timer script running too fast 1 Answer

How to use the same script on different objects at the same time? 1 Answer

Start timer on button press 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