- Home /
Question by
Programming-squad · Sep 03, 2017 at 11:24 AM ·
c#animationjavascript
Play animation on mouse click
I want a C# or JS code to play my animation when I click left mouse button!
Comment
Best Answer
Answer by DimitriUK · Sep 03, 2017 at 01:36 PM
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");
}
}
Answer by SohailBukhari · Sep 03, 2017 at 11:43 AM
function Update() {
if(Input.GetMouseButtonDown(0))
animation.Play();
}
Your answer
Follow this Question
Related Questions
The problem of Enemy scale when he follow the player (script) . How to fix? 0 Answers
How call a animation in Spine by a Javascript? 0 Answers
Attack animation Wont Play 1 Answer
iTween Rotation not exact 0 Answers
Distribute terrain in zones 3 Answers