From 4f40c9c06f4a8592719eb437bfd78ef6ea40922b Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Mon, 24 Feb 2014 13:48:53 +0000 Subject: [PATCH] New AddButton() and RemoveButton() room methods Use AddButton() to make any sprite clickable Use RemoveButton() to remove clickable functionality --- Assets/Fungus/Scripts/Button.cs | 41 +++++++------ Assets/Fungus/Scripts/Commands.cs | 60 +++++++++++++++++++- Assets/Fungus/Scripts/Room.cs | 12 ++++ Assets/FungusExample/Scenes/Example.unity | Bin 70112 -> 67608 bytes Assets/FungusExample/Scripts/SpritesRoom.cs | 12 +++- 5 files changed, 104 insertions(+), 21 deletions(-) diff --git a/Assets/Fungus/Scripts/Button.cs b/Assets/Fungus/Scripts/Button.cs index ab3e8b97..ceb15ca6 100644 --- a/Assets/Fungus/Scripts/Button.cs +++ b/Assets/Fungus/Scripts/Button.cs @@ -1,4 +1,5 @@ using UnityEngine; +using System; using System.Collections; using Fungus; @@ -10,25 +11,34 @@ namespace Fungus [RequireComponent (typeof (BoxCollider2D))] public class Button : MonoBehaviour { - public string methodName; - + public Action buttonAction; public SpriteRenderer spriteRenderer; - public bool autoDisable = false; - - void Start() - { - spriteRenderer = GetComponent(); - } - - void OnMouseUpAsButton() + // Makes a sprite into a clickable button + public static void MakeButton(SpriteRenderer _spriteRenderer, Action _buttonAction) { - if (methodName == "") + if (_spriteRenderer == null) { + Debug.LogError("Sprite renderer must not be null"); return; } - // Ignore button press if button is not fully visible + // Remove any previous button component that was added + Button oldButton = _spriteRenderer.gameObject.GetComponent