Hello,
Just to clear things up, I want to know an easy way to increase, or decrease a value over time (seconds) as apposed to the frame.
So normally, if I wanted to increase a value, I would just do value++ in the update, which increases the value every frame. What about every second? Is there an easy way to do that within an update?
Thanks
There is a simple value that translates between seconds and frames. If you want to increment a floating-point number evenly over time, you can use
number += Time.deltaTime;
Over one second it will increase by one.
However, if you want to increment an int exactly once a second, you can use a coroutine:
int incrementThis = 0;
IEnumerator NumberIncrementer(ref int number)
{
while(true)
{
yield return new WaitForSeconds(1);
number++;
}
}
void Start()
{
StartCoroutine(NumberIncrementer(ref incrementThis));
}
void Update()
{
Debug.Log(incrementThis);
}
This way it will increment the number exactly once a frame.