Search Unity

Bug Animation not playing when I press button (SetTrigger)

Discussion in 'Animation' started by garg0499, Sep 11, 2023.

  1. garg0499

    garg0499

    Joined:
    May 30, 2023
    Posts:
    1
    I'm trying to make this 2D character play an attack animation when I do left click, I know I cannot do that with just Animator.Play because its only playing for the frame which Input.GetMouseButton(0) is true, right?

    So I checked online and I saw that I had to use a trigger parameter instead, because its true then after the animation is done, its not true, so it would work.

    This is the code



    Code (CSharp):
    1. if (Input.GetMouseButton(0))
    2.         {
    3.             anims.SetTrigger("Attacking");
    4.         }
    And this is the animator:



    As you can see all seems to be set correctly and then here you can see compiling the game, it even triggers true when I click the mouse, but the transition from idle to attack doesnt happen:




    What could be wrong here?

    Thank you for your time and help!