Hi
I need to check a variable second by second. How could I do it?
Thank You
Hi
I need to check a variable second by second. How could I do it?
Thank You
In the Update method, check the variable. If you need a delay so it’s not checked every frame, just keep a counter of when you last checked it, and don’t until it’s been more than a second. Reset and repeat.
Or use a coroutine, yielding a null (to wait a frame) or a WaitForSeconds (to wait a duration).
Something like this
private float timeSinceLastCheck = 0f;
private float timeBetweenChecks = 1f;
void Update()
{
timeSinceLastCheck = timeSinceLastCheck + Time.deltaTime;
if (timeSinceLastCheck >= timeBetweenChecks)
{
checkTheVariable();
timeSinceLastCheck = timeSinceLastCheck - timeBetweenChecks;
}
}
private void checkTheVariable()
{
//Do whatever check you need to here
}