- Home /
How can I call an animation via script?
Hello guys,
I have a game and really need some help. I have a sprite sheet with the sprites. I created an Animation Clip that has these 3 animations. I want that when I press space bar, I will have the animation done.
So here is what is happening. I tried many ways, but none worked. I have the Clip set as legacy, and am using actually a script that gets an Animation object, attached to the player, and tries to get the clip named "Player", that is attached to the object in the hierarchy. This didn't work. I have tried other things, but haven't got a good result.
I have searched all I could, read many posts but I just haven't managed to find how I would do this. I also read the documentation, but haven't found any solution.
Can someone please help me? Thanks!
Answer by KurtLorey · Apr 07, 2015 at 12:13 PM
Add an animator to your gameobject, link your animation controller to that and then call each animation from code
var animator:Animator;
function Start(){
animator=GetComponent(Animator);
}
function Update()
{
if (Input.GetKeyDown() {
animator.Play("NAME OF ANIMATION");
}
I am doing C#. Could you write the code for me in C# please?
If you still need help email me $$anonymous$$urtlorey@gmail.com
I fixed it using the Animator. Anyway thanks for the help!
Your answer
Follow this Question
Related Questions
Play animation OnTriggerEnter (C#) 1 Answer
Is there a way to abstract sprite from animation clip? 0 Answers
Model has Animator, how do I force start an animation, and tell where it is? (C#) 1 Answer
**Help please?**How do I activate my jump animation? (It's just 1 frame) 1 Answer
Animation keeps playing 2 Answers