Script for running animation.

Hi. I followed a guide that showed how to make some animation. I cam to a halt when i tried to add the running animation. This is the script im using

` //Controls Player Movement
public float movementSpeed = 10.0f;

//Controls Player Jump
private int jumpHeight = 500;
public bool isGrounded = false;

//Reference
Animator anim;

// Use this for initialization
void Start () {
	anim = GetComponent<Animator> ();

}

// Update is called once per frame
void Update () {

	anim.SetFloat ("speed", Mathf.Abs (Input.GetKey ("left"))); 

(this is where the “Argument #1' cannot convert bool’ expression to type `float’” error comes.

“speed” is a parameter for the animation. The guy i follow uses
“anim.SetFloat (“speed”, Mathf.Abs(Input.GetAxis (“Horizontal”)));”. Whats the difference here?

	//Control PLayer Left Movement
if (Input.GetKey ("left") || Input.GetKey ("a")) {
		transform.position -= Vector3.right * movementSpeed * Time.deltaTime;
	    //transform.eulerAngles = new Vector2(0,180);
	}
	//Control PLayer Right Movement
if (Input.GetKey ("right") || Input.GetKey ("d")) {
		transform.position += Vector3.right * movementSpeed * Time.deltaTime;
		//transform.eulerAngles = new Vector2(0,0);

    }`

See:

This tells you that GetKey() returns a bool. The compiler is telling you that this bool cannot be converted into a float. If you compare with GetAxis() you’ll see that that returns a float.