Answer by LukaKotar
Update() is not coroutine, and I don't think you can change that. You could try making a 'while' loop in an IEnumerator. Start the coroutine in Start(), and the 'while' loop will cause it to repeat...
View ArticleAnswer by Eric5h5
You should not use Update for this, since Update always runs once every frame and cannot be delayed in any way. IEnumerator Start () { yield return new WaitForSeconds (Random.Range (8, 12)); // Do stuff }
View ArticleAnswer by Owen Reynolds
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...
View ArticleAnswer by AlexHogan
Your Coroutine is fine - nice jobe. The problem is that update is sending the event every frame, so your coroutine is starting every frame. Just change void Update() { StartCoroutine(GenerateEvent());...
View ArticleAnswer by LukaKotar
`Update()` cannot be a coroutine, but you could create a `while` loop inside of an `IEnumerator` to achieve your desired behavior. Start the coroutine in `Start()`, and the loop will cause it to repeat...
View ArticleAnswer by Eric5h5
You should not use Update for this, since Update always runs once every frame and cannot be delayed in any way. IEnumerator Start () { yield return new WaitForSeconds (Random.Range (8, 12)); // Do stuff }
View ArticleAnswer by Owen-Reynolds
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...
View ArticleAnswer by AlexHogan
Your Coroutine is fine - nice jobe. The problem is that update is sending the event every frame, so your coroutine is starting every frame. Just change void Update() { StartCoroutine(GenerateEvent());...
View ArticleAnswer by bullze
You can do it like bool isCoroutineReady = true; void Update() { if(isCoroutineReady) { isCoroutineReady = false; StartCoroutine(yourCoroutine()); } } IEnumerator yourCoroutine() { //your Code...
View ArticleAnswer by vbs
Why use `InvokeRepeating` https://docs.unity3d.com/ScriptReference/MonoBehaviour.InvokeRepeating.html From the documentation: `Invokes the method methodName in time seconds, then repeatedly every...
View ArticleAnswer by ysleungrockman
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 =...
View Article