0
votes

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 is a bool type parameter. I drag the script which controls they behaviours and animator component on gameobject, 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());
 }

Animator: animator

Gameobject: gameobject that keeps script

1
Does it play second animation when you manually set the bool to true in the Animator window in Play Mode?Kashif Siddiqui
Also how does the Animator window look like? What's the active animation in Play mode?Kashif Siddiqui
First of all, I solved the problem, but it was very awkward. Because I just set the animator public and attached it. Isn't it "getcomponent" get component on the component which attached to gameobject? And when I set the bool to true it was playing, but when the player clicks it was turning into true, but it wasn't playing. Get the point, it was very awkward and I still don't know the problemAiden Martinez
In general for this kind of transition better use a Trigger and SetTrigger() instead of a boolderHugo

1 Answers

0
votes

This problem occurs because of your Animator. You should call Animator on Canvas game object (Not on Menu Manager). Just change your script to this:

void Start () {
 canvasAnim = GameObject.Find("Canvas").GetComponent<Animator>();
 ...
}

I hope it helps you.