Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Tycellent · Sep 05, 2015 at 10:13 AM · timerwaittimer countdown

Getting a timer to go to 0

Hey everyone,

What i'm trying to do is after the timer goes to 0 i'd like for the timer to stop for 2 seconds and then reset and thus the process will repeat. What i have so far is...

     public GUIText timerText;
     public float timer = 0.0f;
     public float timerMax;
 
     void Start()
     {
         timer = timerMax ;
     }
 
     void Update()
     {
         if (timer <= 0.0f)
         {
             StartCoroutine(wait(2.0f));
             timer = timerMax;
         }
 
         else
         {
             countdown();
         }
     }
 
     void countdown()
     {
         timer -= Time.deltaTime;
         updateTimerText();
     }
 
     IEnumerator wait(float waitTimer)
     {
         yield return new WaitForSeconds(waitTimer);
     }
 
     void updateTimerText()
     {
         timerText.text = "Timer: \n" + Mathf.Round(timer * 10f) / 10f;
     }

This is also used with a GUIText to print out the timer but that shouldn't really matter. The issue at the moment is that it's not stopping for the 2 seconds. I think this might be due to it not reaching 0 but then again the timer does reset so i'm not too certain.

Any help will be appreciated!

Comment
Add comment · Show 2
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 hexagonius · Sep 05, 2015 at 10:27 AM 1
Share

in essence, you need your Coroutine to repeat itself, because it's already waiting. you could wrap the yield in a while true and call whatever you need to be called after the 2 seconds after the yield. Start the coroutine in start.

avatar image Tycellent · Sep 05, 2015 at 11:32 AM 0
Share

@hexagonius, awesome you were right. Thanks for the help!

1 Reply

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

Answer by Tycellent · Sep 05, 2015 at 11:33 AM

If anyone is interested, just as @hexagonius said i just had to use a while loop :)

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

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

Related Questions

Traffic Light won't change colors State machine 0 Answers

Change the Intensity of a Haptic Feedback with respect to time ? 0 Answers

Simple timer using InvokeRepeating 2 Answers

How do I create a timer. 1 Answer

Clock doesn't stop when reaches 0.0. Can you help me with this. 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