Animation does not work

In my scene there is a character (a troll) and a First Person Character, like in the picture.

The troll has to states: “Walk” and “Idle_02”. A bool variable “walking” insures to pass from Idle_02 to Walk (walking = true) and Walk to Idle_2 (walking = false).
The code is attached to Trol character and is as follows:

 #pragma strict

		public var walking: boolean = false;
		public var anim: Animator;
		public var currBaseState: AnimatorStateInfo;
		public var walkState: int = Animator.StringToHash("Base.Walk");
		public var idleState:int = Animator.StringToHash("Base.Idle_02");
		private var playerTransform: Transform;
		private var hit: RaycastHit;

		function Start () {
			anim = GetComponent(Animator);
			playerTransform = GameObject.FindGameObjectWithTag("Player").transform;

		function Update () {
			currBaseState = anim.GetCurrentAnimatorStateInfo(0);
			var distance:float = Vector3.Distance(transform.position, playerTransform.position);
			Debug.Log("Current base state: " + currBaseState);
				case idleState: Debug.Log("Idle state !!!!!!!!!!!!!");
								if ((Physics.Raycast(Vector3(transform.position.x,
				                                             transform.forward, hit,40) &&
		                                                     hit.collider.gameObject.tag == "Player") || distance <4.0f){
				case walkState: Debug.Log("Walk state !!!!!!!!!!!!!");
				default: 		Debug.Log("Default state !!!!!!!!!!!!!");
			transform.rotation.x = 0.0;
			transform.position.y = -0.5;
			transform.rotation.z = 0.0;

If I get closer to troll, it should walk to the player. But when I play the troll stays in Idle_02 state.

currBaseState is always in default state. The message in console is “Default state !”. It does not change the state.

Weird. Could you show a picture of your animator with the parameters?

Perhaps one of these is the issue:

  • Your missing transitions in the animator
  • You haven’t assigned “anim” in the inspector
  • Your animations did not import correctly

This is the animator;