How do I make a UI Buttion play an Animation when pressed?
I have two animations, one is idle, the other is just an animation of an object moving. I was able to GetKeyDown to work with the keyboard, but am having a heard time figuring out how to make a UI button activate the animations instead of a key press. The button names are Idle and Animate. What would I need to put in for a On Click () command?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class gearclockAnimController : MonoBehaviour {
public Animator gearclockAnim;
// Use this for initialization
void Start () {
gearclockAnim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetButton ("Animate"))
{
gearclockAnim.Play ("gearclockExplode");
}
if (Input.GetButton ("Idle")) {
gearclockAnim.Play ("gearclockIdle");
}
}
}
Comment