Hi guys! First time here! Thanks for having me. Anywho, I’ve ran into a problem where my character object is only showing their run animation when I move up and down. I’m trying to show the run animation by going left and right as well. Thanks in advance… Here is my code…
public class PracPC : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent ();
}
void Update ()
{
}
// Update is called once per frame
void FixedUpdate () {
float moveup = Input.GetAxis (“Vertical”);
float moveright = Input.GetAxis (“Horizontal”);
anim.SetFloat (“Speed”, Mathf.Abs (moveright));
anim.SetFloat (“Speed”, Mathf.Abs (moveup));
GetComponent().velocity = new Vector2(moveupmaxSpeed, GetComponent().velocity.y);
GetComponent().velocity = new Vector2(moverightmaxSpeed, GetComponent().velocity.x);
if (moveright > 0 && !facingRight)
Flip ();
else if (moveright < 0 && facingRight)
Flip ();
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}