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?
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.