- Home /
GUI button play animation
Hello, I got a problem on using Button play animation. I can press the button and animation can be played. But It seems the animation cannot be repeated or play inverse if i click in the button again. Is the process can be done in animator? thank you
Here is my script:
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class play_anim_on_ui_button : MonoBehaviour {
public Button Text;
public AudioClip sound;
public Animator ani;
public Canvas yourcanvas;
void Start ()
{
Text = Text.GetComponent<Button> ();
ani.enabled = false;
yourcanvas.enabled = true;
}
public void Press()
{
Text.enabled = true;
AudioSource.PlayClipAtPoint(sound, transform.position);
ani.enabled = true;
Destroy(Text,1);
yourcanvas.enabled = true;
}
}
screen-shot-2017-06-11-at-213751.png
(76.0 kB)
screen-shot-2017-06-11-at-213739.png
(43.4 kB)
Comment
Your answer
Follow this Question
Related Questions
Play Animation on Button Press 1 Answer
Play the same animation with 3 different buttons? 1 Answer
How to play two animations with one button? 2 Answers
Play animation when in collider and button pressed 1 Answer
Button animation state stays Pressed or Highlighted after disabling GameObject 0 Answers