I want to slowly decrease a float, kinda something like Time.deltatime.
I tried “speed–;” but its way to fast.
I want to decrease it from something like 2 to 0 really slow, is there a fast and easy way to do this in c#?
Thanks you for reading!
I want to slowly decrease a float, kinda something like Time.deltatime.
I tried “speed–;” but its way to fast.
I want to decrease it from something like 2 to 0 really slow, is there a fast and easy way to do this in c#?
Thanks you for reading!
In your Update() function, you could run something like this:
speed = Mathf.Clamp(speed - acceleration * Time.deltaTime, minSpeed, maxSpeed);
If acceleration
is positive, speed will increase by that many units per second; if negative, it’ll decrease. You could use 0 and 2 for minSpeed
and maxSpeed
.
maybe you want something simpler than what proposed rutter ? something as simple as:
speed -= 0.1f
which is equivalent to speed = speed - 0.1f