using UnityEngine; using System.Collections; public class Walk : MonoBehaviour { public float speed = 3f; Animator animator; // Use this for initialization void Start() { animator = this.GetComponent(); } // Update is called once per frame void Update() { float y = Input.GetAxisRaw("Vertical"); float x = Input.GetAxisRaw("Horizontal"); transform.position += new Vector3(x * speed * Time.deltaTime, y * speed * Time.deltaTime, 0f); if (y > 0) { animator.SetInteger("Direction", 2); } else if (y < 0) { animator.SetInteger("Direction", 0); } else if (x > 0) { animator.SetInteger("Direction", 1); } else if (x < 0) { animator.SetInteger("Direction", 3); } else if(x == 0 && y == 0) { animator.SetInteger("Direction", 4); } } }