The function won’t return out of Update
, only itself. The code in Update
will continue to execute after the function. In this case, the return in the function is unnecessary because it’s the last thing that will happen anyway.
You’d want to return a value that you can check in Update
. Something like this
private bool PeriodIsZero() // <- return a boolean
{
if (Mathf.Approximately(period, 0f)) // <- this checks if period is _almost_ 0, but _almost_ 0 will actually be fine
{
Debug.LogWarning("period cannot = 0!"); // <- log a warning instead of just a message (could be error, too)
return true; // <- return true, because the function checks if period is zero, and here it is
}
return false; // <- period is not zero
}
and then you can use this in Update
private void Update()
{
if (PeriodIsZero()) { return; } // <- call the function, and exit if it returns 'true'
}
Note: I changed the function name, but it can be whatever you feel is needed