Mecanima Scripting Animations

Im trying to work with mecanim but its poorly documented and sparsely talked about. I have the model all set up, the animator states and the script. But it just wont transition the states. Im trying to make a small scene, player presses ‘W’ character walks forward. In the animator i have two states: Idle and Walk Forward. The trigger is float Speed, if the speed is greater than 0.1 the character moves, less than 0.1 character is idle, problem is, it just stays stuck in Idle, when running the scene and watching the animator the progress bar under Idle never starts. I think the script is the problem, but ive been at this for a while and im loosing patience.

And finally the script:

using UnityEngine;
using System.Collections;

public class AliceSpades : MonoBehaviour 
{

	public Animator Spades;
	private float speed;

	// Use this for initialization
	void Start () 
	{

	}
	
	// Update is called once per frame
	void FixedUpdate () 
	{
	
		if (Input.GetKey(KeyCode.W)) //if key is W change speed to trigger transition
		{
			speed = 0.2f;
		} 
		else //else character is idle
		{
			speed = 0.0f;
		}
		Spades.SetFloat("Speed", speed);//update speed
	}
}

Alright i found one of the problems, i changed the animation speed to zero, Its at one now allowing for better animation. However, my script is still not working the proper way. I have to keep pressing on it repeatedly to even get the animator to register it. And it only works once.

Follow below steps :

  1. Attach this script on player

  2. Create an Animator Controller, then add 2 state ‘Idle’ & ‘Walk’, by right clicking create state > empty

  3. Drag your animation clips into it

  4. Create parameter named ‘Walk’ of integer type by clicking on ‘+’ sign at upper right corner

  5. Make transition from ‘Idle’ state to ‘Walk’

  6. Click on transition Idle → Walk, Add a condition below

  1. Make transition from ‘Walk’ state to ‘Idle’

  2. Click on transition Walk → Idle, Add a condition below

  1. Add animator component on your player game object, and drag your animator controller into it.

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

     public static PlayerController instance;
     private Animator animPlayer;
     
     public int walkSpeed = 10, rotateSpeed = 2, angle = 0;
     
     float xVal, zVal;
     
     void Start () {
     	instance = this;
     	animPlayer = GetComponent<Animator>();
     }
     
     void Update ()  {
     	
     	// Calculating user input through key board **************************************
     	xVal = Input.GetAxis ("Horizontal");
     	zVal = Input.GetAxis ("Vertical");
    
     	// Player walk **************************************************
     	if (zVal >= 0.1f) {
     		animPlayer.SetInteger ("Walk", 1); // transition Idle -> Walk
     		transform.Translate(Vector3.forward * Time.deltaTime * walkSpeed);
     	}
     	else {
     		animPlayer.SetInteger ("Walk", 0); // Player stays in Idle state
     	}
    
     	// Player rotate **************************************************
     	if(xVal >= 0.1f ) {
     		angle += rotateSpeed;
     		transform.localEulerAngles = new Vector3(0, angle, 0);
     	}
     	else if(xVal <= -0.1f ) {
     		angle -= rotateSpeed;
     		transform.localEulerAngles = new Vector3(0, angle, 0);
     	}
    
     }
    

    }