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 /
This question was closed Apr 30, 2013 at 11:47 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by Shaheera · Apr 30, 2013 at 10:17 AM · timecountdowntimer countdownitemspick up

How to make a time based game?

Hi,

I have made a game but I want to make it time-based and I don't know how to do that.

Example: Game is supposed to be 10 minutes long and as the player progresses through the game, the time should decrease until it reaches 0 (which means game over).

Also, my game requires to pick up certain items which increase the time for the player. Example: The time to complete the game is 10 mins. When the player is down to the 5th minute, he picks up a pencil. This items increases his time to 7 mins. How do I do that?

Please help. Thanks a lot.

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 Fattie · Apr 30, 2013 at 11:47 AM 0
Share

use Invoke() or InvokeRepeating() for simple timers in Unity. this is the most asked question on the site. search for 10,000s of questions on timers, invoke, yield, time.deltatime etc etc. unityGE$$anonymous$$S.com for many good beginner articles on it

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by Fornoreason1000 · Apr 30, 2013 at 10:33 AM

Time.DeltaTime is your friend here. just make a timer that decreases by Time.DeltaTime that is making a var that starts at 10(minutes) or 600(seconds) then decreases it each frame in Update().

in the timer script just make a function that adds to the timer, this will get called when the player revives and item.

Displaying the time as Min:Sec IS little more tricky, but still easy in the grand scheme of things. ToMinutes

 float minutes = Mathf.Floor(timer / 60).ToString("00");
 float seconds = (timer % 60).ToString("00);
 

when the timer reaches zero use a Quit Function or a game over function. now there other questions like this. http://answers.unity3d.com/questions/45676/making-a-timer-0000-minutes-and-seconds.html

http://answers.unity3d.com/questions/25614/how-do-i-format-a-string-into-daysminuteshoursseco.html

http://answers.unity3d.com/questions/200733/timetime-as-minutes-and-seconds-.html

and about 20 others in the Related Questions

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
avatar image
0

Answer by HannesR · Apr 30, 2013 at 10:33 AM

Have a variable called timeLeft set to 600 (for 10 mins). In Update just subtract Time.deltaTime from it. To add time, just add the amount of seconds to it.

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

Follow this Question

Answers Answers and Comments

15 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

Related Questions

How to subtract 1 from an int each second? 2 Answers

How to have a real-time countdown timer that continues even if the app is exited? (For someone who has no idea about servers and connecting to the internet via code) 1 Answer

countdown timer starts from the begining when i reLaunch the app 1 Answer

Why does my MatchTime Class not work when using Properties? 1 Answer

Coroutine Countdown Timer being extremely slow 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