Ok, i’m working on my top down rpg game, and i have a problem when i try to make the character play the animation when it’s moving to the left,right. it only plays the animation when it’s moving up and down, i’m not an expert at programming, but i don’t know what is wrong. it is only 1 animation,character flips depending if it’s moving left or right. Here’s the code:
using UnityEngine;
using System.Collections;
public class Controller : MonoBehaviour {
public float walkSpeed = 10f;
Animator animator;
void Start()
{
animator = GetComponent<Animator> ();
}
void Update () {
animator.SetFloat ("Speed", Mathf.Abs (Input.GetAxisRaw ("Horizontal"))); //This plays the animation.
if (Input.GetAxis ("Horizontal") > 0) {
transform.Translate (Vector3.right * walkSpeed * Time.deltaTime);
transform.eulerAngles = new Vector2(0,0); //This sets the rotation of the character while moving to the Right.
}
if (Input.GetAxis ("Horizontal") < 0) {
transform.Translate (Vector3.right * walkSpeed * Time.deltaTime); //Vector3.right because of rotation, next line.
transform.eulerAngles = new Vector2(0,180); //This sets the rotation of the character while moving to the left.
}
animator.SetFloat ("Speed", Mathf.Abs (Input.GetAxisRaw ("Vertical"))); //This plays the animation.
if (Input.GetAxis ("Vertical") > 0) {
transform.Translate (Vector3.up * walkSpeed * Time.deltaTime);
}
if (Input.GetAxis ("Vertical") < 0) {
transform.Translate (Vector3.down * walkSpeed * Time.deltaTime);
}
}
}