I have a float value that I would like to decrease by 10.f per second; for example
floatx - 10f * 'second'
How can I get real time seconds or another form of time in unity?
The easiest way to do this would be in Update:
var -= 10.f * Time.deltaTime;
or, if the variable you are modifying is going to be affecting the movement of a physics object, then in fixedUpdate:
var -= 10.f * Time.fixedDeltaTime;
or if you alter your deltaTime for any reason (such as to create a slow motion effect) and you want this to happen in real time seconds regardless of this
// in update
var -= 10.f * Time.unscaledDeltaTime;
or if it's altering something about a physics object
// in fixedUpdate
var -= 10.f * Time.fixedUnscaledDeltaTime
All these will reduce your variable by 10 per second
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.