Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

animator.SetBool from behavior in that same animator?

Discussion in 'Animation' started by TangerineDog, Mar 9, 2021.

  1. TangerineDog

    TangerineDog

    Joined:
    Oct 20, 2020
    Posts:
    20
    In my Player Animator, I've added this to an animation's behavior:
    Code (CSharp):
    1. public class Attack_Finished : StateMachineBehaviour
    2. {
    3.     public Animator animator;
    4.  
    5. public void OnStateExit()
    6.     {
    7.         animator.SetBool("Attacking", false);
    8.     }
    9.  
    10. }
    11.  
    However, when I try to set the animator in the Inspector, the Player animator doesn't show.

    How then do I have a bool in the animator set from inside that animator when an animation ends?
     
  2. TangerineDog

    TangerineDog

    Joined:
    Oct 20, 2020
    Posts:
    20
    Since the bool change corresponds to a mouse click, I worked around it by detecting a click in my PlayerController and setting one bool there that in turn modifies the one in the animator.

    Code (CSharp):
    1.         if (Input.GetMouseButtonDown(0))
    2.             Attacking_Sword = true;
    3.         else
    4.             Attacking_Sword = false;
    5.  
    6.         if (Attacking_Sword == true)
    7.             animator.SetBool("Attacking_Sword", true);
    8.         if (Attacking_Sword == false)
    9.             animator.SetBool("Attacking_Sword", false);
    10.  
    Of course, this might only work for others if they face that priblem in a similar context.