In the process of studying Game Development, I decided to do a game of my own. However, while I was putting my animations on my model through the "Animator" tab, I stumbled upon a problem. I have created a parameter of type "float" in the animator, where if the speed is greater or less than the value x, it plays a certain animation. However, in order to instantiate the walking/running speed, I am using a field which is located in the Inspector tab. The problem is that since the initialized speed is always different than 0, the animator uses that inserted value and plays the walking animation despite the fact that no key is pressed!
I have already tried various things that I found online such as, using the "Parameter" checkbox on the animations or using different lines of code such as "animator.SetFloat("Speed", (speed));" on my script but none of these have worked out.
// Update is called once per frame
void Update()
{
//animator.SetFloat("Speed", Mathf.Abs(speed));
animator.SetFloat("Speed", (speed));
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(horizontal, 0f, vertical) * speed * Time.deltaTime;
transform.Translate(moveDirection);
I expect the output to be as follows: when no key is pressed, Idle animation to play. when WASD keys are pressed, walking animation to play. when Shift + WASD keys are pressed, running animation to play.