Play animation of a 3d model (74637)

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?

2 Answers

2

You should always put the name of the animation in “animation.Play(“Take 001”)”. So I think you should change the animation.Play(); into → transform.animation.Play(“Take 001”);

Hope this helps :smiley:

p.s. I don’t know if TRANSFORM infront of animation will work. So, if it doesn’t work after putting transform.animation.Play(“Take 001”); then delete transform from it.

Thanks for the reply, but it still doesn't work.

Did you attach the script TO THE GAMEOBJECT THAT HAS THE ANIMATION?

Sorry for caps, that was to make it bolded :D

I found a solution: 3d model → Rig Tab (Inspector) → Animation Type → Legacy

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