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
-1
Question by yce · Jan 19, 2014 at 06:59 PM · gameobjecttimetimescaledeltatime

Game over scene when the time is up ?

How can i do game over scene when the time is up in this code ?

using UnityEngine; using System.Collections;

public class Timer : MonoBehaviour { public float Seconds = 59; public float Minutes = 0; void Update () { if (Seconds <= 0) { Seconds = 59; if (Minutes >= 1) { Minutes--; } else { Minutes = 0; Seconds = 0; GameObject.Find ("TimerText").guiText.text = Minutes.ToString ("f0") + ":0" + Seconds.ToString ("f0"); } } else { Seconds -= Time.deltaTime; } if(Mathf.Round(Seconds) <= 9) { GameObject.Find ("TimerText").guiText.text = Minutes.ToString ("f0") + ":0" + Seconds.ToString ("f0"); } else { GameObject.Find ("TimerText").guiText.text = Minutes.ToString ("f0") + ":" + Seconds.ToString ("f0"); } } }

Comment
Add comment · Show 1
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 Graham-Dunnett ♦♦ · Jan 19, 2014 at 07:00 PM 1
Share

It's worth watching the tutorial video to learn how to format your code.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DRProductions · Jan 19, 2014 at 10:02 PM

First off make sure you format your code second make a script called Countdown or something and use this code JavaScript:

 var Minutes = 1; 
 function Start(){
 yield WaitForSeconds(Minutes * 60);
 Application.LoadLevel("NAMEOFSCENE");
 }

Or if you prefer C# (This may not work I don't use C# but you get the idea):

 public class Example : MonoBehaviour {
 public int Minutes = 1;
     void Start() {
 
         yield return new WaitForSeconds(Minutes * 60);
 
     }
 }
Comment
Add comment · Show 2 · 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 yce · Jan 19, 2014 at 11:30 PM 0
Share

I tried but didnt work. Also i didnt find tutorial for c#

avatar image DRProductions yce · Jan 20, 2014 at 12:41 AM 0
Share

Are you sure you applied my script? it should work correctly

avatar image
0

Answer by Lasent · Jan 20, 2014 at 01:50 AM

Unfortunately, in C#, Coroutines aren't that easy to start as in US. Here's how it should look: public int minutes = 1;

 IEnumerator GameOver()
 {
 yield return new WaitForSeconds(minutes * 60);
 Application.LoadLevel("GAMEOVERSCENE");
 }
 
 ...
 
 void Start () //Countdown will begin when you load in the script
 {
 StartCoroutine(GameOver());
 ...
 }

In C#, you explicitly have to set the method IEnumerator, and start it with StartCoroutine.

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

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

TimeScale = 0 crashes Unity 1 Answer

2nd independent deltaTime and timeScale variables, or a way to mimic this? 1 Answer

speed change in standalone compared to editor? 1 Answer

Pause game that not using deltatime for movment 1 Answer

Accurate timing while using timeScale. 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