1
\$\begingroup\$

I have made an animation for a button in unity's UI prefab, but i want it to start only at certain times, when i command it with code. How can i do this?

\$\endgroup\$
2
0
\$\begingroup\$

So i did this: The button is for jumping, and as long as you hold your finger on it, it will loop the animation. So in the code where i coded the game to check when the +Y force should be added to the player, i set the button to button.GetComponent<Button>().interactable = true;, and when the force shouldn't be added, to button.GetComponent<Button>().interactable = false;. For this to work, you should add this to the cs file: public Transform button;, and in the editor, add the ui button to the script.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.