diff --git a/Assets/Fungus/Prefabs/Button.prefab b/Assets/Fungus/Prefabs/Button.prefab new file mode 100644 index 00000000..7059dc3a Binary files /dev/null and b/Assets/Fungus/Prefabs/Button.prefab differ diff --git a/Assets/Fungus/Prefabs/Button.prefab.meta b/Assets/Fungus/Prefabs/Button.prefab.meta new file mode 100644 index 00000000..c6a9f627 --- /dev/null +++ b/Assets/Fungus/Prefabs/Button.prefab.meta @@ -0,0 +1,4 @@ +fileFormatVersion: 2 +guid: 2830c354320dd41fb8c7fe61f592942c +NativeFormatImporter: + userData: diff --git a/Assets/Fungus/Scripts/Button.cs b/Assets/Fungus/Scripts/Button.cs index 8cd8a415..fa0ad2d5 100644 --- a/Assets/Fungus/Scripts/Button.cs +++ b/Assets/Fungus/Scripts/Button.cs @@ -10,55 +10,110 @@ namespace Fungus * When the user taps on the sprite, an Action delegate method is called */ [RequireComponent (typeof (SpriteRenderer))] - [RequireComponent (typeof (Collider2D))] public class Button : MonoBehaviour { - public SpriteRenderer spriteRenderer; - public bool autoDisplay; + /** + * Delegate method to call when the player clicks the button. + */ public Action buttonAction; /** - * Makes a sprite clickable by attaching a Button component (and BoxCollider2D if required). - * @param _spriteRenderer The sprite to be made clickable - * @param _buttonAction An Action delegate method to call when the player clicks on the sprite + * Automatically hide the button when displaying story text/options or waiting. + */ + public bool autoHide; + + /** + * Hide the button when a value is set. + */ + public string hideOnFlag; + + float targetAlpha; + bool showButton; + + /** + * Set visibility of a button object and set the delegate method to call when clicked. + * If the object does not already have a Collider2D component, then a BoxCollider2D is added. + * @param _visible Setting this to true makes the button visible, unless overridden by property settings + * @param _buttonAction An Action delegate method to call when the player clicks on the button */ - public static void MakeButton(SpriteRenderer _spriteRenderer, bool _autoDisplay, Action _buttonAction) + public void Show(bool _visible, Action _buttonAction) { - if (_spriteRenderer == null) + SpriteRenderer spriteRenderer = renderer as SpriteRenderer; + if (spriteRenderer == null) { Debug.LogError("Sprite renderer must not be null"); return; } - // Remove any previous button component that was added - Button oldButton = _spriteRenderer.gameObject.GetComponent