Browse Source

Added RemoveAndFadeButton() command

master
chrisgregan 11 years ago
parent
commit
1c563183ea
  1. 3
      Assets/Fungus/Scripts/Commands.cs
  2. 15
      Assets/Fungus/Scripts/GameController.cs
  3. 3
      Assets/FungusExample/Scripts/ButtonRoom.cs

3
Assets/Fungus/Scripts/Commands.cs

@ -474,7 +474,7 @@ namespace Fungus
} }
/** /**
* Makes a sprite stop behaving as a clickable button * Makes a sprite stop behaving as a clickable button.
*/ */
public class RemoveButtonCommand : CommandQueue.Command public class RemoveButtonCommand : CommandQueue.Command
{ {
@ -493,6 +493,7 @@ namespace Fungus
public override void Execute(CommandQueue commandQueue, Action onComplete) public override void Execute(CommandQueue commandQueue, Action onComplete)
{ {
// Remove the button component
Button button = spriteRenderer.gameObject.GetComponent<Button>(); Button button = spriteRenderer.gameObject.GetComponent<Button>();
GameObject.Destroy(button); GameObject.Destroy(button);

15
Assets/Fungus/Scripts/GameController.cs

@ -387,6 +387,21 @@ namespace Fungus
commandQueue.AddCommand(new Command.RemoveButtonCommand(spriteRenderer)); commandQueue.AddCommand(new Command.RemoveButtonCommand(spriteRenderer));
} }
/**
* Makes a sprite stop behaving as a clickable button and fades out the button sprite.
* The fade duration is specified in Game.buttonFadeDuration
* This method returns immediately but it queues an asynchronous command for later execution.
* @param spriteRenderer The sprite to be made non-clickable
*/
public void RemoveAndFadeButton(SpriteRenderer spriteRenderer)
{
CommandQueue commandQueue = Game.GetInstance().commandQueue;
commandQueue.AddCommand(new Command.RemoveButtonCommand(spriteRenderer));
FadeSprite(spriteRenderer, 0f, Game.GetInstance().buttonFadeDuration);
}
/** /**
* Sets an animator trigger to change the animation state for an animated sprite. * Sets an animator trigger to change the animation state for an animated sprite.
* This is the primary method of controlling Unity animations from a Fungus command sequence. * This is the primary method of controlling Unity animations from a Fungus command sequence.

3
Assets/FungusExample/Scripts/ButtonRoom.cs

@ -38,6 +38,9 @@ public class ButtonRoom : Room
void OnMusicClicked() void OnMusicClicked()
{ {
PlaySound(effectClip); PlaySound(effectClip);
// Hide this button once the player clicks it
RemoveAndFadeButton(musicSprite);
} }
void OnQuestionClicked() void OnQuestionClicked()

Loading…
Cancel
Save