diff --git a/Assets/Fungus/Scripts/AnimationListener.cs b/Assets/Fungus/Scripts/AnimationListener.cs index 3ebdf4ee..bf44c674 100644 --- a/Assets/Fungus/Scripts/AnimationListener.cs +++ b/Assets/Fungus/Scripts/AnimationListener.cs @@ -3,10 +3,16 @@ using System.Collections; using Fungus; // Listens for animation events -// The string parameter specifies a method name on the active room class +// Usage: +// 1. Attach this script to the animated sprite that you want to listen to for events. +// 2. Add an event on the animation timeline +// 3. Edit the event and choose the 'CallRoomMethod' function +// 4. In the string parameters box, enter the name of the method to call in the active Room's script. public class AnimationListener : MonoBehaviour { - void OnAnimationEvent(string methodName) + // Handler method for animation events + // The string event parameter is used to call a named method on the active room class + void CallRoomMethod(string methodName) { Room room = Game.GetInstance().activeRoom; if (room == null) @@ -14,6 +20,7 @@ public class AnimationListener : MonoBehaviour return; } - room.AnimationEvent(methodName); + CommandQueue commandQueue = Game.GetInstance().commandQueue; + commandQueue.CallCommandMethod(room.gameObject, methodName); } } diff --git a/Assets/Fungus/Scripts/Button.cs b/Assets/Fungus/Scripts/Button.cs index ceb15ca6..77752353 100644 --- a/Assets/Fungus/Scripts/Button.cs +++ b/Assets/Fungus/Scripts/Button.cs @@ -8,13 +8,13 @@ namespace Fungus // Simple button handler class. // When the user taps on the button, the named method is called on ancestor game objects (if it exists). [RequireComponent (typeof (SpriteRenderer))] - [RequireComponent (typeof (BoxCollider2D))] + [RequireComponent (typeof (Collider2D))] public class Button : MonoBehaviour { public Action buttonAction; public SpriteRenderer spriteRenderer; - // Makes a sprite into a clickable button + // Makes a sprite clickable by attaching a Button component (and BoxCollider2D if required) public static void MakeButton(SpriteRenderer _spriteRenderer, Action _buttonAction) { if (_spriteRenderer == null) @@ -30,7 +30,12 @@ namespace Fungus Destroy(oldButton); } - // This will automatically add a BoxCollider2d if none currently exists + // Add a BoxCollider2d if none currently exists + if (_spriteRenderer.gameObject.GetComponent() == null) + { + _spriteRenderer.gameObject.AddComponent(); + } + Button button = _spriteRenderer.gameObject.AddComponent