Unity 2d toolkit, play specific clip

I am trying to play a specific clip on input. I want it to change clips, from the idle (it starts out as this clip) to the Begin Run clip. I have a animated sprite with both of these clips included. I think there is a simple syntax for this but I just can’t figure it out.

I’ve tried this code, John is the name of the player object,

function Update (){
	if(Input.GetKey == "d"){
		player.transform.position += Vector3(forwarddirection, 0,0);
		John.Play	("Begin Run");
	}
}

I’ve tried 2dTK’s example for playing specific clips

function Update (){
	if(Input.GetKey == "d"){
		player.transform.position += Vector3(forwarddirection, 0,0);
	        Tk2dAnimatedSprite.Play	("Begin Run");
	}
}

I’ve even tried the name of my animated sprite

function Update (){
	if(Input.GetKey == "d"){
		player.transform.position += Vector3(forwarddirection, 0,0);
		AnimatedSprite.Play	("Begin Run");
	}
}

None of it works. Should I be using a static sprite batcher instead of an animated sprite? please help.

1 Answer

1

I found out my problem. I have to define a variable not just use tk2danimatedsprite.
for those that have my problem, I will post this so that you can get help

var animatedSprite : tk2dAnimatedSprite;

animatedSprite = gameObject.GetComponent(tk2dAnimatedSprite);

animatedSprite.Play("begin run");

I hope this helps, Ithe problem also might have been that I use javaScript, and t2tk uses c. Hope this helps

I forgot to note, you must configure for java script before this will work in java script. That was another problem I had.

hi im having same problem I think what do u mean define a variable which variable please help im having troubles and cant figure out