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.