From 21b15329c6531e77365c4603b25a69f0d38245ba Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 18 Oct 2016 15:48:24 +0100 Subject: [PATCH] Added WaitForFrames property to GameStart event handler. Default is wait for 1 frame (to reduce startup order issues). --- .../Fungus/Scripts/EventHandlers/GameStarted.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Assets/Fungus/Scripts/EventHandlers/GameStarted.cs b/Assets/Fungus/Scripts/EventHandlers/GameStarted.cs index 39891c41..70d4667e 100644 --- a/Assets/Fungus/Scripts/EventHandlers/GameStarted.cs +++ b/Assets/Fungus/Scripts/EventHandlers/GameStarted.cs @@ -2,6 +2,7 @@ // It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) using UnityEngine; +using System.Collections; namespace Fungus { @@ -13,9 +14,19 @@ namespace Fungus "The block will execute when the game starts playing.")] [AddComponentMenu("")] public class GameStarted : EventHandler - { - protected virtual void Start() + { + [Tooltip("Wait for a number of frames after startup before executing the Block. Can help fix startup order issues.")] + [SerializeField] protected int waitForFrames = 1; + + protected virtual IEnumerator Start() { + int frameCount = waitForFrames; + while (frameCount > 0) + { + yield return new WaitForEndOfFrame(); + frameCount--; + } + ExecuteBlock(); } }