diff --git a/Assets/Fungus/FungusScript/Scripts/CommandCopyBuffer.cs b/Assets/Fungus/FungusScript/Scripts/CommandCopyBuffer.cs index 0311910c..40e78c57 100644 --- a/Assets/Fungus/FungusScript/Scripts/CommandCopyBuffer.cs +++ b/Assets/Fungus/FungusScript/Scripts/CommandCopyBuffer.cs @@ -35,7 +35,7 @@ namespace Fungus return instance; } - protected override void Start() + protected virtual void Start() { if (Application.isPlaying) { diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index da3b2a8b..ea0190b8 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs @@ -115,6 +115,32 @@ namespace Fungus return false; } + /** + * Sends a message to this Fungus Script only. + * Any sequence with a matching MessageReceived event handler will start executing. + */ + public virtual void SendFungusMessage(string messageName) + { + MessageReceived[] eventHandlers = GetComponentsInChildren(); + foreach (MessageReceived eventHandler in eventHandlers) + { + eventHandler.OnSendFungusMessage(messageName); + } + } + + /** + * Sends a message to all Fungus Script objects in the current scene. + * Any sequence with a matching MessageReceived event handler will start executing. + */ + public static void BroadcastFungusMessage(string messageName) + { + MessageReceived[] eventHandlers = GameObject.FindObjectsOfType(); + foreach (MessageReceived eventHandler in eventHandlers) + { + eventHandler.OnSendFungusMessage(messageName); + } + } + /** * Start running another Fungus Script by executing a specific child sequence. * The sequence must be in an idle state to be executed. diff --git a/Assets/Fungus/FungusScript/Scripts/Sequence.cs b/Assets/Fungus/FungusScript/Scripts/Sequence.cs index 15478681..2d07ea85 100644 --- a/Assets/Fungus/FungusScript/Scripts/Sequence.cs +++ b/Assets/Fungus/FungusScript/Scripts/Sequence.cs @@ -26,7 +26,7 @@ namespace Fungus protected int executionCount; - protected virtual void Start() + protected virtual void Awake() { // Give each child command a reference back to its parent sequence foreach (Command command in commandList)