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 08, 2014 at 02:47 AM · scoretimer-scriptgameover

Timer Score display on Game Over Scene?

I finally found away to trigger my game over scene. I attached this script:

 function Update () {
     if(transform.position.y < -2.6){
         GameOver();
     }
 }
 
 function GameOver(){
     Application.LoadLevel("Game Over");
 } 

to my Star prefab.

But now I cannot seem to get the time to show on the game over scene. Think of it like a high score system. The player's job is to last as long as they can and not let one star pass a certain point or they will lose the game, which will automatically take them to the game over scene. How do I display the player's timer score?

Here is my timer 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; 
 }
  
 var bestScore = 0;
 var playerTime = 0;
 //When the race is completed;
 bestScore = playerTime;
 //Reset playerTime to zero
 //Display the best score(Score to beat)
 //If the next drivers playerTime is higher than the previous bestScore
 if(playerTime > bestScore){
   //Display the new best score.
  //Reset playerTime to zero
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NoseKills · Jun 08, 2014 at 05:30 AM

You'll have to store the values you want to preserve from one scene to another either in to static variables or GameObjects that you make permanent by calling DontDestroyOnLoad on them. You just need to remeber to reset or null, and/or Destroy() these variables when appropriate to prevent unwanted duplicates and accumulating/wrongly initialized values.

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

22 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

Related Questions

How do I carry over canvas ui text to the next scene 2 Answers

Time Score? 1 Answer

How To Show Score On End Game 1 Answer

Playerprefs When the value I set is zero, there is a 2x increase in the part I get. when i close and reopen the game it only shows the last value. How can ı solve these? 1 Answer

High score value remains constant in game over scene, even if player has scored higher. 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