play animation of a 3d model

I have a 3d model of a gun and I added it in the scene. Within the model there is an animation “Take 001” so i created a js script:

function Start () {
 
}
 
function Update () {
    if(Input.GetButtonDown("Fire1")){
       animation.Play();
    }
}

and I added it to the model. But when (in game) I press the left mouse button the animation doesn’t start. I also tried to replace “animation.Play();” with “animation.Play(“Take 001”);” but nothing has changed.

What’s wrong?

ps. I have also tried with transform.animation.Play(“Take 001”); but doesn’t work.

Have you set the rig? Unity 4 needs to be told what sort of rig: None, Legacy, Generic, and Humanoid. If you haven’t done so, click on the imported model in the Project window and then Rig and select legacy and hit apply. That usually what causes my animations to not play.

Thanks for the reply. It works fine, but now there is a new problem caused by that change. The 3d object is moved when I start the game.
Scene: http://gyazo.com/dcbb8224e520241642b7e8f6e7476fac.png
Game: http://gyazo.com/744e09d687d968595972efd0c7d48abb.png

That’s the dreaded “animation-locks-it-in-world-space-issue”. Drop the object into your scene at its origin; i.e. wherever it lands when you drop it in the hierarchy not the scene and then put an empty game object on top of it and parent it to that. Then move the empty game object instead of the model. You’ll need to account for this extra level in your animation scripts. There may be other ways, but that is the only way I know.

I tried to do what you told me and it works. But when I insert the script for the animation, there is the same problem.