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 Zypher · Jun 05, 2014 at 09:57 PM · timergameover

Display Time At Game Over Scene

I have this time script:

 #pragma strict
 private var startTime : float;
 var textTime : String;
 //First define two variables. One private and one public variable. Set the first variable to be a float. 
 //Use for textTime a string. 
 function Start() {
 startTime = Time.time;
 }
 function OnGUI () {
 var guiTime = Time.time - startTime; 
 //The gui-Time is the difference between the actual time and the start time.
 var minutes : int = guiTime / 60; //Divide the guiTime by sixty to get the minutes.
 var seconds : int = guiTime % 60;//Use the euclidean division for the seconds.
 var fraction : int = (guiTime * 100) % 100;
  
  textTime = String.Format ("{0:00}:{1:00}:{2:00}", minutes, seconds, fraction); 
 //text.Time is the time that will be displayed.
  GetComponent(GUIText).text = textTime;
  
 }

Stars all falling and the player's job is to destroy the stars by touching them and they cannot let one pass or they will lose the game. The score system is basically the time; how long they last. But, I'm having trouble with creating a game Over trigger and displaying the player's highest time in the Game Over scene. How do I do it?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jeff-Kesselman · Jun 05, 2014 at 09:58 PM

Move var guiTime to outside of your functions to make it a global

make an Update() function that checks guiTime and, if guiTime is > your time end, load the score scene.

be aware that score will be reset when the scene changes unless you make it a global static

Comment
Add comment · Show 3 · 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 Zypher · Jun 05, 2014 at 10:45 PM 0
Share

Do I just move this line?

 var guiTime = Time.time - startTime; 
 
avatar image Jeff-Kesselman · Jun 05, 2014 at 10:58 PM 0
Share

No, just move the declaration

 var guiTime;

That makes it visible to multiple methods.

THEN change the use in OnGui so it doesn't redefine it:

 guiTime = Time.time - startTime; 

FInally, write an Update method that checks it.

Alternately, as noted below, you could us e a global boolean, set it in your time code and check it in update. Same difference.

avatar image Zypher · Jun 06, 2014 at 01:46 AM 0
Share

I will try your way first.

avatar image
0

Answer by Tekksin · Jun 05, 2014 at 10:42 PM

Just wrap it in a boolean:

 var gameOver : boolean;
 
 function Update(){
    if(!gameOver){
       //do everything you listed in your script
    } else{
       //use the vars in (!gameOver) to get the time amounts to post here, but be sure not to include the accruing code. 
       //show the information of game over.
    }
 }
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 Zypher · Jun 06, 2014 at 01:44 AM 0
Share

Wrapping? I'm confused.

Sorry I'm rather new at this.

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

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

Display Time At Game Over Scene 1 Answer

How can I display the GAME OVER word across the centre of the screen when the when my timer hits zero? 3 Answers

Time Score? 1 Answer

Project Hyerarchy problem? 0 Answers

my timer isnt working for my firerate! it instantiates too many objects at a time,HOw can i get my shot timer working properly? it instantiates too many objects at a time 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