Unity3D Problem Temporarily Stop Players Movement When Playing a specific Animation

This is my first time in Unity3D and programming so forgive me if i'm a bit vague on this. I'm working on my own project in Unity3D but I couldn't get the player to stop moving when I press the key. I avoided using the GetButton since it triggered the animation to play twice. After bout 2 hours, I still can't find any answer to my problem.

Can someone help me please?

Here's part of the code of the the player script.

    if (Input.GetButtonDown("Fire1"))
    {
        animator.SetTrigger("AttackSword");
        Debug.Log("Animation called");
    }

    if(!animator.GetBool("AttackSword"))
    {
        Move(inputDir, running);
    }

If you would like me to add the full code of the script, let me know.

Answers 1

  • I decided to experiment other codes and see if it works and I found out about this code and it works like a charm.

        if (!this.animator.GetCurrentAnimatorStateInfo(0).IsName("AttackSword"))
        {
            Move(inputDir, running);
        }
    

    Even though the transition isn't smooth, I still find it satisfying to solve this problem on my own.


Related Questions