Unity animations not working

hi, I have tried many times to get animations to play with my gun when i press certain buttons. I have imported my gun from blender, and have made the animations on unity using the animation window. I have tried 2 different types of animation script so far, and none have worked.

First Script:

 function Update()
{ if(Input.GetMouseButtonDown(0))
{ // Plays the fire1 animation - stops all other animations 
animation.Play("Shoot", PlayMode.StopAll); } }

Second Script:

if(Input.GetKeyDown("Fire1") && !animation.IsPlaying("Shoot")) 
{ animation.Play("Shoot"); }

Also when i play game, the animation for walking starts automatically without any scripts. Is there a way to stop this? And why won’t my animations work? Please help. Thanks

i think you have set animation of walking as default animation in your player object, you should set it as a animation, not a default animation…please re-check the inspector…

Second thing,
make your script like this.

function Update()
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
animation.Play("Shoot");
}
}

and check your inspector and make sure Shoot animation is present in you animation list or not.

Check in the console for the errors generated during run-time…

hope this helps…

What do you mean by re-cording my animations? Does it mean to make it all again? Its says my scripts are trying to access ‘animation’.
I’ve been able to set the gun to legacy, and add all my animations into the play button component.

Thanks for all the help and it is really appreciated!