- Home /
How do I change the animation in Javascript?
I have a model. I want a function that changes the Animator Controller to a action/animation I have in my assets.
Answer by Thuynder · Jul 18, 2013 at 01:45 AM
If you want to play a animation on a model in the scene, you can add the animation component to the object, then drag in the animation for that object into the animations in the component. Once you do that, you can access it from a script like this.
function Start()
{
var player : GameObject = GameObject.Find("name"); // name of player
player.animation.Play("idle1"); // just play the animation
player.animation.CrossFade("idle1"); // fade smoothly into it
}
This isn't what I was asking. I have the component in. I just need the function to change it. I need more info. For example: where is idle1 located? Where is it being accessed from? How do I choose one buried in the assets.
You drag the idle1 animation into the animation component, under animations, you can choose how many animations there are, just drag one into a slot.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110333im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I animate a 2D sprite? 1 Answer
Javascript Movement Script. Why am I getting these errors? 2 Answers
Animating Function Calls 0 Answers
Activate a component when an animation clip in an animator is played? 0 Answers
Camera Move 1 Answer