My two solutions

First with an attribute:

[SerializeField, Min(0.1f)] float period = 2f;

Second way with an if statement in Update():

void Update()
    {
        period = period < Mathf.Epsilon ? 0.1f : period;
    }

I like the first one more because this way the designer can’t even try to put in a negative value.
Edit: changed the sacond way to be in Update instead of Start because otherwise the game will still crash if someone changes the period during runtime.

2 Likes

Privacy & Terms