-1
\$\begingroup\$

I'm trying to make walk animation. But when I try to change animation idle to walk, ıt doesn't work. It says 'Parameter "Walk" doesn't exist'but I added parameter and script works. I can manually change parameter and it works(walk animation is playing). But when I try to change via script, ıt doesn't work.

enter image description here

Here are codes

public class Controller : MonoBehaviour

private Rigidbody rb;

private float xPos;

Vector3 playerMovement;

[SerializeField] Animator anim;

private void Awake() => rb = GetComponent<Rigidbody>();

private void Start()
{
    xPos = transform.position.x;
}

// Update is called once per frame
void Update()
{
    Move();
}

private void Move()
{
    float mH = Input.GetAxis("Horizontal");
    playerMovement = new Vector3(0, 0, mH);
    rb.AddForce(playerMovement * 2f);
    anim.SetFloat("Walk", 1);
    transform.position = new Vector3(xPos, transform.position.y, transform.position.z);
}
\$\endgroup\$
3
  • \$\begingroup\$ Can you show us the object with this script selected in the Inspector, so that we can see both this script and the animator component it's referencing? \$\endgroup\$
    – DMGregory
    Apr 20, 2021 at 23:16
  • \$\begingroup\$ I removed animation clip and then readd. It solved. Thanks for you answer \$\endgroup\$
    – Apoleytaa
    Apr 21, 2021 at 0:24
  • \$\begingroup\$ Want to share your solution as an Answer below? \$\endgroup\$
    – DMGregory
    Apr 21, 2021 at 0:39

2 Answers 2

0
\$\begingroup\$

I think you need to check if anim field that attached have the same animator controller you show on the screenshot. It should work the name is the same. And also you can have this warning if Controller script attached to the model that does not contain "Walk" variable in animator.

\$\endgroup\$
0
\$\begingroup\$

I removed animation clip and then readd. It solved.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .