2D Toolkit Animation won't begin.

I’m writing a script for touch screen input in which the player character will be animated through 2D Toolkit when a GUI button is touched. This is my script so far, and I can’t seem to work out how to get it to work.

Each time I drag the character I want to animate into the “Animated Sprite” variable of the inspector, it resets to “None” at runtime.

The rest of the code involving the player having rigidbody.drag changed to 3.000 works perfectly. The keyboard version of this script works as well. Can anyone help?

My code so far is:

var Player : GameObject;

var animatedSprite : tk2dAnimatedSprite;

animatedSprite = gameObject.GetComponent(tk2dAnimatedSprite);

function Update () {

var fingerCount = 0;

for (var touch : Touch in Input.touches) {

    if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled && guiTexture.HitTest(touch.position))

        fingerCount++;

}

if (fingerCount > 0) {

   Player.rigidbody.drag = 3.000;

   animatedSprite.Play("Jumped");

   animatedSprite.animationCompleteDelegate = null;



}

}

The 2D Toolkit wiki and sample code are wrong on this one: just calling ‘Play’ every frame will constantly restart the animation.

You have to check whether the animation is playing already, and if it’s not, start playing it again (provided you didn’t have it on loop).

It’s a brutal solution, but this worked well enough in a recent project (C#):

void playAnim(tk2dAnimatedSprite theSprite, int theClip)
{
	if (theSprite.clipId != theClip)
	{
		theSprite.Play(theClip);
	}
}