It’s must be as simple as Animation.Play(), right?
What I want: GameObject (“Shell”) instantiated and fly towards the target. When it’s reached target, it change shell’s sprite to chain of explosion sprites, then Destroy ()
What I have : gameObject “shell” with:
Sprite Renderer (with sprite
“shell”)
shell_script
Animator
Animator have “ProjectileShell” Controller, which contain “explosion” animation
problem is animation is played by default, and Ican not figure out how to get to it thru script. Add animation straight to GameObject is Legacy and, more than that, i can’t get it working too(
if you want to use Animator component (Mecanim), you need to:
create Animation Controller - in top menu Assets / Create / Animation Controller
attach the AnimationController to the Animator Component
open window Animator - in top menu Window / Animator
select the gameObject with the Animator (AnimatorController attached) and in Animator window you see state machine scheme (actually no scheme now, the AnimatorController is empty, but you can have it there)
drag animations (made for the particular gameObject) to the Animator window and you will make states from the animations this way
name states as you wish (not bad idea to leave them with the same name as animations)
you can pass variable to Animator (Mecanim) and start transitions in it):
But if the default state is your required animation state, then your animation will be played automatically since thats the default state of animation
So create an idle state in Animator and Set as Default(Yellow Color) and then make transition to your required animation state from idle, based on a trigger/bool/float/int parameters.
else you can directly Play the animation as well without parameters by doing the above. But using those parameters are helpful.