Ok, Now I’m smart and I’m using a boolean. Pressing W changes the value in the animator window to true and triggers a walk animation. But releasing W, does nothing, the boolean stays true.
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public float speed = 6.0F;
public float rotationSpeed= 12.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
public Animator anim;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
if (Input.GetKey (KeyCode.A))
transform.Rotate(Vector3.up * Time.deltaTime * -rotationSpeed);
if (Input.GetKey (KeyCode.D))
transform.Rotate(Vector3.up * Time.deltaTime * rotationSpeed);
if (Input.GetKey (KeyCode.W))
anim.SetBool ("walk", true);
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}