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 spunktrumpet · Dec 17, 2013 at 03:22 PM · timetimer

Timer running down too quickly

I have two timers running, they both trigger one another so when one reaches just below 0 it triggers the other to start until it reaches just below 0. The thing is the timers are running down extremely quick, although they are set at 30, they run down in a bout 5 seconds. Any ideas? I've tried setting the Time.timeScale = 1 but that changes nothing.

 public static float timerOff = 30;
 public static float timerOn = 0;
 private bool isTiming = true;
 // Use this for initialization
 void Start ()
 {
     Time.timeScale = 1.0f;
 }

 // Update is called once per frame
 void Update ()
 {
     if (isTiming == true)
     {
         timerOff = timerOff - 1 * Time.deltaTime;
         if(timerOff < 0)
         {
             isTiming = false;
             timerOn = 30;
         }
     }

     if (isTiming == false)
     {
         timerOn = timerOn - 1 * Time.deltaTime;
         if (timerOn < 0)
         {
             isTiming = true;
             timerOff = 30;
         }
     }

     print(timerOff + "off");
     print(timerOn + "on");
 }
Comment
Add comment · Show 6
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 fafase · Dec 17, 2013 at 03:23 PM 2
Share

Do you this on two objects or more?

avatar image GameVortex · Dec 17, 2013 at 03:36 PM 0
Share

That script works fine for me, it counts down in exactly 30 seconds. $$anonymous$$aybe you can try debugging out what Time.deltaTime is for you? Do you have anything else in your scene? Try using the script alone in a new project and see if that works.

avatar image spunktrumpet · Dec 17, 2013 at 04:16 PM 0
Share

Only using it on one object, it was working fine the first few times I tried it, after changing some other things it started to do this. I changed the other things back however the time is still going at this speed. By the looks of it the script is fine, it's just something glitchy, just wanted to know if it was the script or not causing the problem.

avatar image fafase · Dec 17, 2013 at 04:26 PM 1
Share

In the Start of your script add:

  Debug.Log("D'oh!!");

just to make sure you would not have it twice

avatar image fafase · Dec 18, 2013 at 06:03 AM 1
Share

You could also make sure you only have one:

 static ClassName _instance = null;
 
 void Awake(){
    if(_instance == null)_instance = this;
    else Destroy(this);
 }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Melih Şimşek · Dec 17, 2013 at 03:42 PM

I suggest you to use

 timerOff -= Time.deltaTime;

Instead

 timerOff = timerOff - 1 * Time.deltaTime;
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 spunktrumpet · Dec 17, 2013 at 04:14 PM 0
Share

Tried that already, tried all different ways of using Time.deltaTime I can think of.

avatar image fafase · Dec 17, 2013 at 04:25 PM 0
Share

Your suggestion is the exact same thing as his.

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

19 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

Related Questions

Timer help please 1 Answer

How would you make your player freeze for a certain amount of time? 2 Answers

A node in a childnode? 1 Answer

Unity and Playmaker - Flashlight Decrease Logic 0 Answers

Move game object over time with GetButtonDown 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