Hi all. I have created an animation, a simple scale a position change. Now if I place that animation on my game object, the “Animator” component then gets added, at this point the animation starts looping or playing once, I don’t want this, I want it to not play at all at the beginning and to be able to call it from script and play it.
If I try to remove the “Animator” component, my “Animation” component doesn’t play at all. setting it to “play automatically” or trying to call it from the script does not work. It just doesn’t do anything. What am I missing? Do I need the animator component attached to a game object to play an animation or can I do without it and control it myself? It seems like the animator is connected to mechanim, but do you really need to use mechanim to play simple animations?
Ok I think my problem was the fact that I was adding animations to the prefabs as apposed to their instances, as in the prefabs in the Project panel instead of the Hierarchy panel. Apparently, adding animations to objects that don’t exist in the scene isn’t a good idea.
So if you have a prefab in your project you need to add animation to, drag it into the hierarchy panel, add the animation and replace the prefab of it(the one in your project panel) with this new one and it should work once that prefab is instantiated.
@pencilking2002 Hi! I was also trying to call/ Play an animation through script and couldnt find any link that can help me. I am new to Unity, Sorry.
I was aiming for something like this.
if (condition < 0){
GetComponent(Animation).Play("My Animation");
}
else{
GetComponent(Animation).Play("My Animation");
}
}
I couldn’t find a simple procedure for this.
Thank you!