Answer the question
In order to leave comments, you need to log in
How to start animation on click in unity?
I just started learning unity and I need to start the sprite animation on button click, I need the script itself
Answer the question
In order to leave comments, you need to log in
ui button? You make a public method, and in it you launch the animation you need by the number (or how you wrote it down). And then in the button you select this method.
public void fuckingclick(){ //публичный метод (виден в редакторе)
Animator anim = this.GetComponent<Animator>(); //присваиваем animator, где есть нужная анимация (this - этот обьект, вместо него можно/нужно префаб).
anim.setInteger("shit", 1); //запускаеться анимация shit:1.
}
{
Animator anim;
void Start(){
anim = this.GetComponent<Animator>(); //присваиваем animator, где есть нужная анимация (this - этот обьект, вместо него можно/нужно префаб).
}
void Update(){
if(Input.GetKeyUp(KeyCode.space))//если отжата space
anim.setInteger("shit", 1); //запускаеться анимация shit:1.
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question