Trying to change an animation with a UI button
I'm a total noob at Unity and don't know c#, so the struggle is real. All i'm trying to do is change my main character's idle animated state to its happy animated state with a UI button click. What code do I need for that?
Answer by UnityCoach · Dec 03, 2016 at 08:26 PM
Good news! You don't need code ;)
1 : Add a Trigger parameter to your Animator Controller
2 : Add a Transition Condition using the Trigger
3 : On the UI Button object, add an OnClick event, drag the object with the Animator component in the field on the left, on the right, select Animator>Set Trigger (string), then give it the name of the trigger parameter.
I would use code, but for a quick prototype, that works.
Answer by Tamra9991 · Dec 03, 2016 at 08:35 PM
Oh my lord... it actually worked!! @jikkou Is there any way to have the trigger interrupt the animation? I notice that it waits for the first animation to finish before switching. Can it immediately switch once the button is clicked?
You can set this in the transition parameters. Note that you can have multiple transitions between two states, one may interrupt, while the other is a smoother transition for example.
Oh my, you genius you!!! Thank you so much, works perfectly!
Your answer
Follow this Question
Related Questions
Animator consecutive set parameter problem 0 Answers
Survival shooter - Video 2 - Movement Animation Not Working 1 Answer
Advice on how to proceed/Which technique to use [Weapon Animation] 0 Answers
How to get quick animation transition variants on start? 0 Answers
Range Attack + Animation Script 0 Answers