diff --git a/Assets/Fungus/Scripts/Components/DialogInput.cs b/Assets/Fungus/Scripts/Components/DialogInput.cs index 3605bcec..24987ab8 100644 --- a/Assets/Fungus/Scripts/Components/DialogInput.cs +++ b/Assets/Fungus/Scripts/Components/DialogInput.cs @@ -51,8 +51,27 @@ namespace Fungus protected virtual void Awake() { writer = GetComponent(); + + CheckEventSystem(); } + // There must be an Event System in the scene for Say and Menu input to work. + // This method will automatically instantiate one if none exists. + protected virtual void CheckEventSystem() + { + EventSystem eventSystem = GameObject.FindObjectOfType(); + if (eventSystem == null) + { + // Auto spawn an Event System from the prefab + GameObject prefab = Resources.Load("Prefabs/EventSystem"); + if (prefab != null) + { + GameObject go = Instantiate(prefab) as GameObject; + go.name = "EventSystem"; + } + } + } + protected virtual void Update() { if (EventSystem.current == null) @@ -62,17 +81,6 @@ namespace Fungus if (currentStandaloneInputModule == null) { - if (EventSystem.current == null) - { - // Auto spawn an Event System from the prefab - GameObject prefab = Resources.Load("Prefabs/EventSystem"); - if (prefab != null) - { - GameObject go = Instantiate(prefab) as GameObject; - go.name = "EventSystem"; - } - } - currentStandaloneInputModule = EventSystem.current.GetComponent(); } diff --git a/Assets/Fungus/Scripts/Components/Flowchart.cs b/Assets/Fungus/Scripts/Components/Flowchart.cs index a61f40f5..1c1224d4 100644 --- a/Assets/Fungus/Scripts/Components/Flowchart.cs +++ b/Assets/Fungus/Scripts/Components/Flowchart.cs @@ -89,6 +89,8 @@ namespace Fungus #if UNITY_5_4_OR_NEWER protected virtual void Awake() { + CheckEventSystem(); + UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (A, B) => { LevelWasLoaded(); }; diff --git a/Assets/Fungus/Scripts/Components/MenuDialog.cs b/Assets/Fungus/Scripts/Components/MenuDialog.cs index 935d242a..44d76085 100644 --- a/Assets/Fungus/Scripts/Components/MenuDialog.cs +++ b/Assets/Fungus/Scripts/Components/MenuDialog.cs @@ -35,6 +35,25 @@ namespace Fungus // Don't auto disable buttons in the editor Clear(); } + + CheckEventSystem(); + } + + // There must be an Event System in the scene for Say and Menu input to work. + // This method will automatically instantiate one if none exists. + protected virtual void CheckEventSystem() + { + EventSystem eventSystem = GameObject.FindObjectOfType(); + if (eventSystem == null) + { + // Auto spawn an Event System from the prefab + GameObject prefab = Resources.Load("Prefabs/EventSystem"); + if (prefab != null) + { + GameObject go = Instantiate(prefab) as GameObject; + go.name = "EventSystem"; + } + } } protected virtual void OnEnable()