0
\$\begingroup\$

The first time the player clicks a button, my animation plays properly.

The problem is that when the player presses the button a second time, the animation does not play.

Here is the code I'm using to control my animation:

public Animator anim;

public Animator animsfirst;
public Animator animssecond;
public Animator animsthird;

public Animator reanimsfirst;   
public Animator reanimssecond;   
public Animator reanimsthird;   
public Animator closeinstruct; 

public void instructionpanel()      //(instruction panel open animation)
{
    anim.enabled = true;         //when button click instruction panel open
    animsfirst.enabled = true;
    animssecond.enabled = true;
    animsthird.enabled = true;
}

public void closeinstructionpanel()  //(instruction panel close animation)
{
    Debug.Log("animationrun");   //when button click instruction panel close
    reanimsfirst.Play("freverse");
    reanimssecond.Play("srevese");
    reanimsthird.Play("lreverse");
    closeinstruct.Play("clreverse");
}

Here is the animator controller setup for the animsfirst object:

Unity animator controller screenshot

And for the reanimsfirst object:

Unity animator controller screenshot

How can I resolve this issue?

\$\endgroup\$
  • \$\begingroup\$ It looks like you're using six animator controllers here to do the job of one. Have you considered placing your forward and reverse animations into a single controller, and using transitions between the states controlled by a SetTrigger command to handle the switch from forward to reverse? \$\endgroup\$ – DMGregory Jun 24 '19 at 11:46
  • \$\begingroup\$ I did not ask you whether you are currently using it: I can see that you are not. I am telling you that you should investigate it, because it can simplify your work and eliminate some bugs. \$\endgroup\$ – DMGregory Jun 24 '19 at 12:14
1
\$\begingroup\$

On your animator controller, create a new(empty) state, and set it as your default layer, now make a transition from your animation clip to the empty clip. The goal is to let the animator return to it's original state after it has played thereby allowing you to play again as many times possible.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.