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?
-
2\$\begingroup\$ Possible duplicate of Play and Stop Animation on Condition - Unity \$\endgroup\$ – Alchemist Oct 2 '16 at 12:14
-
\$\begingroup\$ @Sam the link gave me the idea bellow. Thanks for that. \$\endgroup\$ – MrChips Oct 6 '16 at 0:09
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.