How to activate animation just when give click on a button

How to activate animation just when give click on a button, is there any tutorial or some code to
manage this issue?

Thanks!

Sample code is simple enough:

using UnityEngine;

public class PlayAnimation : MonoBehaviour
{
    public string animationName;
    Animator anim;
    void Start()
    {
        anim = GetComponent<Animator>();
    }
    public void CallThisFromButton()
    {
        anim.Play(animationName);
    }
}

Attach this script to object with Animator, fill in animationName field and make button call CallThisFromButton() method.

2 Likes

Thanks!