- Home /
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??
Answer by Eric5h5 · Apr 04, 2011 at 06:59 PM
Use InvokeRepeating.
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).
Answer by DaveA · Apr 04, 2011 at 06:55 PM
Please read up on the Time component as well as FixedUpdate function
FixedUpdate is for physics, it's not for ti$$anonymous$$g (among other things, there's no guarantee that it will run the same number of times every second, nor when it will run).
$$anonymous$$ake sure you are using floating point values for emptySpeed?