A
A
AllexPika2021-01-06 17:03:15
Unity
AllexPika, 2021-01-06 17:03:15

How to enable one and disable another animation when clicking on a Button?

How to make it so that when you click on the Button, an additional animation fires, and the first one that is looped at that moment stops, and then immediately the additional animation stops, and the main one (which was initially looped) continues until the next button is pressed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Valferov, 2021-01-07
@walfer2020

Activate and end animations in code, use coroutine to delay time

void buttonClick()
    {
        StartCoroutine(animationControl());
    }
    IEnumerator animationControl()
    {
        anim.SetBool("firstAnimation", false);//выключаем  постоянную анимацию
        anim.SetBool("secondAnimation", true);//включаем временную
        yield return new WaitForSeconds(2);//укажи время проигрывания второй анимации что бы она успела проиграть
        anim.SetBool("firstAnimation", true);//включаем обратно постоянную анимацию
        anim.SetBool("secondAnimation", false);//выключаем временную
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question