I want a C# or JS code to play my animation when I click left mouse button!
C# Version (Legacy Animation):
void Update() {
if (Input.GetMouseButtonDown(0))
{
animation.Play();
}
}
C# Version (Mecanim Animation)
public Animator anim;
void Start()
{
anim = GetComponent<Animator>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
anim.SetTrigger("YourAnimation");
}
}
function Update() {
if(Input.GetMouseButtonDown(0))
animation.Play();
}