Although it is very old question, I think I found a way that actually works:
void Update()
{
StartCoroutine(GenerateEvent());
}
IEnumerator GenerateEvent()
{
enabled = false;
int _wait = Random.Range(8, 12);
yield return new WaitForSeconds(_wait);
enabled = true;
}
`enabled` only enables/disables `Update()` and it does not affect the CoRoutine so by putting `enabled = false` and `enabled = true` in, it would not run every frame. (However, thing I do not know is if it would affect the performance too much, so it may not be the best answer.)
↧