The title explains it all. How would I code a function that subtracts 1 from an integer each second?
Like this:
int someInt;
void Start()
{
InvokeRepeating("Subtract", 1f, 1f);
}
void Subtract()
{
someInt -= 1;
}
Try “InvokeRepeating” I think the 2.0f is for the delay and then the .3f is for repeating every .3 seconds (or the opposite), you’d need to check that for certain. But basically, it calls the function every .3 seconds after a certain delay and does whatever the function asks…in your case you will subtract 1 from an integer.
void Start()
{
InvokeRepeating("CallThisFunction", 2.0f, 0.3f);
}
void CallThisFunction()
{
Here, you would subtract one from the integer.
}