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 RadhaUnity3d · Mar 05, 2014 at 11:43 AM · timer-script

How to create a Game Time in mm:ss format

Hello every -body....I want to create a Time Inside a game..which starts with 00:00...when player hit start button ...and it should display ..in GUI texture..or GUI.Label.... first second should be loaded after that minutes ....any help would be great appreciable....

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 vivekkalkur · Mar 05, 2014 at 12:08 PM 0
Share

Have you been through this link? : http://answers.unity3d.com/questions/45676/making-a-timer-0000-$$anonymous$$utes-and-seconds.html

1 Reply

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

Answer by SirCrazyNugget · Mar 05, 2014 at 12:23 PM

Standalone script:

 #pragma strict
 
 private var timerOn : boolean; //if the timer is running or paused
 private var timerCount : float; //the actual timer
 private var timerStart : float; //the point in time the timer was started
 private var timerString : String; //the display string for the timer
 
 private var timerRect : Rect = Rect(10, 10, 200, 100);
 private var startRect : Rect = Rect(10, 210, 100, 40);
 private var resetRect : Rect = Rect(110, 210, 100, 40);
 
 
 function Update () {
     
     if(timerOn){
         timerCount = Time.time - timerStart;
     }
     
     var seconds = Mathf.Floor(timerCount % 60);
     var minutes = Mathf.Floor(timerCount / 60);
     timerString = String.Format("{0:00}:{1:00}", minutes, seconds);
 }
 
 function OnGUI(){
     
     //if timer is counting
     if(timerOn){
         if(GUI.Button(startRect, "Stop")){
             timerOn = false; //toggle timer
         }
         
     //if timer has stopped
     }else{
         if(GUI.Button(startRect, "Start")){
             timerOn = true; //toggle timer
             timerStart = Time.time - timerCount;
         }
     }
     
     //reset the timer
     if(GUI.Button(resetRect, "Reset")){
         timerOn = false;
         timerCount = 0;
     }
     GUI.Label(timerRect, timerString);
 }

Enjoy!

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 RadhaUnity3d · Mar 07, 2014 at 06:43 AM 0
Share

Thx for Great help!!!!

avatar image RadhaUnity3d · Mar 07, 2014 at 06:56 AM 0
Share

Thanks for the GReat help!!!!!!

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 to set On Screen Message w/ timer 3 Answers

How do I create a mission timer? 2 Answers

Minutes and Seconds in a text 1 Answer

timer not ticking down 2 Answers

Changing texture after 3s,4s and 5s 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