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
    Commented Jan 23, 2016 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\$ Commented Jan 27, 2016 at 4:20
  • \$\begingroup\$ Jon's answer below gets you what you need \$\endgroup\$
    – DMGregory
    Commented Jan 27, 2016 at 7:18

1 Answer 1

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\$ Commented Jan 27, 2016 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
    Commented Jan 27, 2016 at 10:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .