How to animate my 2D sprite button when clicking the sprite.

Heya Fellas,

I’m trying to get my button (2d sprite, with sprite sheet) to animate on click.

I have the animations, I have some basic scripts and have animated on click before but I can’t get my little 2d sprite to do it.

I’m guessing It doesn’t work the same way for a 2d element as a 3d one.

I have a 2d collider set, i have the animations all set.

I used this code on the 3d version of the button but i’m trying to get a 2d sprite version happening.

#pragma strict

var playing : boolean = false;

function OnMouseDown()

{
	
   	if (!playing) {

      playing = true;

      animation.Play("Button_001");

      yield WaitForSeconds(animation["Button_001"].length);

      playing = false;

   }

}

function Start () {

}

function Update ()

{

  

}

Any and all hep would be much appreciated

Morph

You should use mecanim then all you do is

 Animator anim = GetComponent<Animator>();
 anim.SetBool("boolName",true);

But first you need to set your animation tree and states.