cannot get parameters to function correctly in 2D animation

i have a 2D sprite that currently has an “Idle”, “frontstep”, and “backstep” animation. since there are 3 walking anims i made it an int parameter. my problem lies when i press play scene and my character automatically does the “frontstep” animation and no matter which button i press, the character still plays the frontstep animation.

i know where the problem is but i cant seem to find a solution.

here is my code:

using UnityEngine;
using System.Collections;

public class playermovement : MonoBehaviour 
{
	         public int speed = 2;

	          Animator anim;

	void Start ()
	{
		anim = GetComponent<Animator>();
	}

	void Update () 
		{
		
		anim.Integer("speed", move);
	
		if(Input.GetKey(KeyCode.D))
			transform.Translate(Vector2.right * speed * Time.deltaTime);
		
		if(Input.GetKey(KeyCode.A))
			transform.Translate(-Vector2.right * speed * Time.deltaTime);
	}


}

i realize that the problem is in “public int speed = 2;” because the speed parameter displays a 2 automatically but i havent been able to find a way around this.

thanks in advance for any commentary.

Is this what you’re going for? I probably got the integer wrong that corresponds to backstep, frontstep, and idle since you didn’t specify those but you can always change the numbers I used.

using UnityEngine;
using System.Collections;
 
public class playermovement : MonoBehaviour 
{
             public int speed = 2;
             private int direction = 0;

 
              Animator anim;
 
    void Start ()
    {
        anim = GetComponent<Animator>();
    }
 
    void Update () 
    {
        direction = 0;

        if(Input.GetKey(KeyCode.D)) 
        {
            transform.Translate(Vector2.right * speed * Time.deltaTime);
            direction = 1;
        }

 
        if(Input.GetKey(KeyCode.A)) 
        {
            transform.Translate(-Vector2.right * speed * Time.deltaTime);
            direction = 2;
        }

        anim.SetInteger("speed", direction);
    }
 
 
}