Decrease a value over time?

Hello,

I basically have a figure that decrease from 100, to 0, and then increases back up to 100.

All I'm basically doing is this: `figure --;` in an update function, which of courses decreases the value every frame.

Is there a way to do this in a controlled manor? (as frame rate is dependent on computer speed)

So .. time?

--UPDATE EDIT--

Okay,

So ive put this in a fixed update:

figure -= (Time.deltaTime * emptySpeed);

And no matter what I turn the emptySpeed number into (except 0) - the figure decreases at the same speed, is there a way to possible slow it down??

2 Answers

2

Use InvokeRepeating.

Please read my update

I tried this - and it still seems like its using frame rates? In the editor the number decreases slowly, and in the build - its reallllyyy fast!

Then you must have done it wrong. Take a look at the example code in the docs (note that there is no Update at all).

Please read up on the Time component as well as FixedUpdate function

FixedUpdate is for physics, it's not for timing (among other things, there's no guarantee that it will run the same number of times every second, nor when it will run).

Please read my update

I stand corrected.

Make sure you are using floating point values for emptySpeed?