Return to Idle animation after Walking animation

I made two animations both Wrap.Mode = Loop (Idle and walking) and I made this script. The problem is that when the player is stopped l ‘animation “Idle” does not start and the player is stuck on’ animation “Walking”.
Help me.

The script.

enum CharacterState 
{
    Idle,
    Walking,
}
public var idleAnimation : AnimationClip;
public var walkAnimation : AnimationClip;
private var _characterState : CharacterState;
function Update() 
{	var v = Input.GetAxis("Vertical");
    var h = -Input.GetAxis("Horizontal");
    
    
    
 	if(v || h)
 	{
 		_characterState = CharacterState.Walking;
 	}
 	else if(v < 0.2  h < 0.2)
 	{	
 		_characterState = CharacterState.Idle;
    }
 
    CheckMovementAnimation();
    
    
    
}

function CheckMovementAnimation()
{
	switch(_characterState)
	{
		case CharacterState.Idle : 
			animation.Play("Idle");
			print("Idle");
			
		break;
			
			
			
		case CharacterState.Walking :
			animation.Play("Walking");
			print("Walking");
			
			
		break;
		
	
	
	}
}

use animation.Stop("Walking");

before playing Idle animation

animation.Stop("Idle"); before playing walking.

Hope this help

It doesn’t work. The Player The player takes the 'Walk" animation even when stationary

Its working fine here one more thing please set Wrap.Mode = Default; in the inspector.

Are you getting your “Idle” debug text to show you that the case is being executed?

@achingupta87 It doesn’t work.
@SteveJ Yes, the case is being exucuted, because it print in console Idle or Walking. I think the problem are the animations.

can you please check you model is it contains two animation or not? If Not please select model set animation in inspector.

It is correct?

1269976--56402--$Screen Shot 2013-06-11 at 1.56.10 PM.pngIt is absolutely correct. I think problem may be in your animation. check model setting in inspector is it same as PNG

Ehm sorry, but how I can check the model setting in inspector from prefab?

Yes, you can’t not check model setting in inspector from prefab . but you can check setting of model without prefab means when we import any model in project window then you can check it easily. check Rig>Animation Type>Legacy.

Sure, but my player was made with cubes of unity so I have not imported anything.

Sorry kryber Now I can not help you more because I don’t no how we play the animation in game object like cubes. I generally use .fbx file which contains already animation I just needs to set some setting in inspector attach a simple script.

ok :frowning: thanks anyway for your time