- Home /
Question by
unity_y4jGTNi9Zvdi5w · Sep 08, 2018 at 01:00 PM ·
animationanimator
Playing animation on button press with a condition
Hi, I want to do menu animation. In the animator, its contain 2 animations. One is opening animation, the other is closing animation. I set the opening animation as default state and added condition between of them. The condition contains one parameter, it is a bool type parameter. I drag the script which controls they behaviours on gameobject and animator component, but when the opening animation plays and player clicks the play button the parameter turns into true but it doesn't play.
Animator canvasAnim;
public Button lvlSelector;
Button lvlSelector_A;
// Use this for initialization
void Start () {
canvasAnim = GetComponent<Animator>();
lvlSelector_A = lvlSelector.GetComponent<Button>();
lvlSelector_A.onClick.AddListener(LevelSelector);
}
IEnumerator SlideLevelSelectMenu()
{
yield return new WaitForSeconds(1f);
SceneManager.LoadScene("LevelSelectMenu");
}
void LevelSelector()
{
canvasAnim.SetBool("clickedclose", true);
StartCoroutine(SlideLevelSelectMenu());
}
this is the script
and this is the animator behaviour
screenshot-5.png
(55.9 kB)
Comment