0
\$\begingroup\$

I want to make a frame Independent Timer that it work consistently across different computer configuration.

\$\endgroup\$
3
  • \$\begingroup\$ Is it game time you want to measure, or realtime? Game time can slow down or speed up if you're modifying Time.timeScale for slow-motion effects and the like. \$\endgroup\$
    – DMGregory
    Jan 23 '16 at 16:22
  • \$\begingroup\$ i just want to make a clock where each time is important and specific event will fire on time. additonally i want to slow and speed up the time ? is this possible \$\endgroup\$ Jan 27 '16 at 4:20
  • \$\begingroup\$ Jon's answer below gets you what you need \$\endgroup\$
    – DMGregory
    Jan 27 '16 at 7:18
2
\$\begingroup\$
// ORIGINAL TIMER COUNTDOWN IN SECONDS
const float TIMER = 3;

// TIMER CURRENT TIME
float Timer;

// RUNS ON EACH FRAME
void Update()
{
    // SUBTRACT DELTA TIME FROM CURRENT TIME
    Timer -= Time.deltaTime;

    // TIMER WENT OFF
    if (Timer <= 0)
    {
        //DO SOMETHING
        Foo();

        // RESET TIMER
        Timer = TIMER;
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ so this will work frame Indepently and how can i speed up \$\endgroup\$ Jan 27 '16 at 9:32
  • \$\begingroup\$ @MohammadFaizanKhan you would change the TIMER value to whatever you want. I added some comments since you seem to be pretty new to this. \$\endgroup\$
    – jgallant
    Jan 27 '16 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.