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 TemplateR · Jul 01, 2014 at 12:14 PM · timerrespawnstoprestart

Restart Level, No restart Timer

Hello,

I´m learing a little scripting (wihh Unity/JavaScript) and its good till now. I have made a countdown-timer for my simple side-scroller game.

The Problem is, that I don´t know, how to reload the level (thourgh respawning) without to restart the timer.

So far this is the timer-script:

pragma strict

//A simple countdown timer var myTimer : float = 10.0;

 function Update () {
  if(myTimer > 0){
   myTimer -= Time.deltaTime;
  }
  if(myTimer <= 0){
  myTimer = 0;
  Application.LoadLevel("GameOver");
  }
 }
 
 function OnGUI(){
 GUI.Box(new Rect(10,10,50,20),"" + myTimer.ToString("0"));
 
 }



Does anyone have a solution?

Comment
Add comment · Show 7
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 koray1396 · Jul 01, 2014 at 02:33 PM 0
Share

What do you mean by "reload the level (thourgh respawning) without to restart the timer"?

From what I could understand, you can define a function "GameOver", run it if the timer goes below 0, and inside GameOver function, you can use Application.LoadLevel("TheNameOfTheLevel");

avatar image TemplateR · Jul 01, 2014 at 03:00 PM 0
Share

If the player is falling from the plattform, the player will respawn in the begnning zone again.

The Problem is, that the the timer will is also restarting, which it shouldn´t be for me.

avatar image RakshithAnand · Jul 01, 2014 at 03:15 PM 0
Share

Oh, by the way i understood , you mean to say when player falls off the platform you want to end the game within that many seconds right?

avatar image TemplateR · Jul 01, 2014 at 03:58 PM 0
Share

No. If the player falls off the plattform, the game will continue. But the the player will be respawn with the latest time on the beginning of the level.

avatar image Klarax · Jul 01, 2014 at 04:00 PM 0
Share

there is a function called DontDestroyOnLoad which is very useful

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by spraw · Jul 01, 2014 at 03:24 PM

You will either have to save the time down to say PlayerPrefs and reload that upon restarting, or (based on your comment on what you're trying to archive) just move the player back to the original position as opposed to fully reloading the level.

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 ethelfxm · Jul 01, 2014 at 05:11 PM 0
Share

$$anonymous$$oving the player to the original position worked for me! I've been killing myself trying to figure this out for days now. Thanks!

avatar image
0

Answer by NorthernVisionStudio · Jul 05, 2014 at 07:44 AM

Two opinions, considering "reload the level through respawning" means that the level data in Unity remains, but the player respawns.

A) make the timer a static variable

or

B) separate the timer into a different game object from the player game object. Therefore, the player can respawn and the timer lives on

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to restart a level with countdown? 4 Answers

Respawn timer? Duplicate instance OnDestroy question... 0 Answers

Timer that stops at the end of the game 3 Answers

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

Coroutine start and stop 2 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