- Home /
Animation doesn't play when calling it with a script!!
My Animation doesn't play when I'm calling it with a script!? I have animation component with a clip called Shot on my object. What's wrong, i have tried everything. Here's my script:
function Update ()
{
if(Input.GetMouseButtonDown(0))
{
animation.Play("Shot");
}
}
Answer by lorainiscool · Feb 24, 2014 at 06:19 PM
Try changing the line to : Animation.Play("Shot"); [Unity is known to have issues with capitalisation]
Answer by screenname_taken · Feb 24, 2014 at 08:32 PM
Are you using an animator component or the older animation component? If you are using the older component or you are getting a warning that the animation needs to be set as legacy, try to set the animation clip as "legacy" if you imported it from a 3D package. If you made it in unity, click the animation clip file in the Project panel, then click the drop down icon next to the lock icon on the top right of the inspector panel, and from the drop down menu select "debug". Then in the box for "animation type" write 1. (That will force it into legacy.)
Also, did you double check in the editor, just to see if the clip is actually connected to the object? I get that sometimes.
$$anonymous$$y animation is 2d sprite animation, i made it in unity, i am using the animation component and i have set my animation clip as "legacy" because it gave me error of that. But still it doesn't work!! And yes i double checked that.
Just a wild stab in the dark here. If there isn't any kind of debug message/ error about the animation, have you tried setting the animation's speed to 1 with animation["Shot"].speed=1; ? Normally it shouldn't be anything less than 1 if it's set to play automatically... I'm sorry i know you are probably frustrated by now but it's the only other thing i can think about.
EDIT: i just found out in a different thread that the 2D animations were built to be used with the animator component, not the animation one if you are using the dope sheet.
Thanx for answer. $$anonymous$$y animations speed is 1... but I'll try to use animator ins$$anonymous$$d. :D
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Mecanim animation and scripting problems 0 Answers
Animation interference problem 1 Answer
Fireflies... 1 Answer
Animation Problems 1 Answer