If you're just starting Unity, maybe skip coroutines completely for now. The best way to do something is a way that makes sense to you. See if this seems more obvious, counting time down to 0, then resetting:
public float secsToNext=0.0f; // public lets you check it running in the Inspector
Update() {
secsToNext -= Time.deltaTime; // T.dt is secs since last update
if(secsToNext<=0) {
secsToNext = Random.Range(8.0f, 12.0f);
// do thing here:
}
....
A coroutine automatically does the countdown for you, so runs a little faster. But if things are allready fast enough, there's no point complicating things.
↧