button click switch animations

so I just want to know how to change the animation from my 2d character when i’m clicking a button. So I’m in a 2D Game, created my character with several animations and a button and now i don’t know what to do
I tried to script something but first, it doesn’t worked well and second, i don’t know if i have to assign the script to the character or to the button OR to a game object
i’m looking at the internet for ours to find the answeres but i can’t find anything

Use the animator. In the animator put your different animation and between them put transition.
In code you have to do : animator.SetTrigger to continue to the next animation.

If you use a button it’s something like GameObject.Find(“myCharacter”).getComponent().SetTrigger(“Triggertest”);

Don’t forget GameObject.Find is not good for performance. Try to make a public variable or at the start make a reference.