Hey,
I'm trying to get a running animation to play when a key is double tapped. When I double tap the key, I get this error:
IndexOutOfRangeException: Array index is out of range.
tk2dAnimatedSprite.Play (Int32 clipId, Single clipStartTime) (at Assets/TK2DROOT/tk2d/Code/Sprites/tk2dAnimatedSprite.cs:353)
tk2dAnimatedSprite.Play (Int32 id) (at Assets/TK2DROOT/tk2d/Code/Sprites/tk2dAnimatedSprite.cs:312)
AnimationManager.AnimationChecker (System.String animationName, .tk2dAnimatedSprite anim) (at Assets/Scripts/AnimationManager.cs:62)
AnimationManager.Update () (at Assets/Scripts/AnimationManager.cs:51)
I'm not too sure why, since I'm using the same code for my walking animations, which still work with the code. here's where I call the animations:
public class AnimationManager : MonoBehaviour {
public InputManager inputManager;
public tk2dAnimatedSprite animSprite;
public string nameAnimation;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(inputManager.keyName == "Left" && inputManager.hasDoubleTapped == true)
{
nameAnimation = "leftRun";
}
else
{
if(inputManager.keyName == "Right" && inputManager.hasDoubleTapped == true)
{
nameAnimation = "rightRun";
}
}
if( inputManager.keyName == "Down" && inputManager.hasDoubleTapped == true && inputManager.isLookingLeft == true)
nameAnimation = "leftRun";
else
{
if( inputManager.keyName == "Down" && inputManager.hasDoubleTapped == true && inputManager.isLookingRight == true)
nameAnimation = "rightRun";
}
if( inputManager.keyName == "Up" && inputManager.hasDoubleTapped == true && inputManager.isLookingLeft == true)
nameAnimation = "leftRun";
else
{
if( inputManager.keyName == "Up" && inputManager.hasDoubleTapped == true && inputManager.isLookingRight == true)
nameAnimation = "rightRun";
}
if (!animSprite.IsPlaying(nameAnimation))
{
AnimationChecker(nameAnimation, animSprite);
}
}
public void AnimationChecker(string animationName, tk2dAnimatedSprite anim)
{
nameAnimation = animationName;
int clipID = anim.GetClipIdByName(nameAnimation);
anim.Play(clipID);
}
}
It's basically supposed to change the animation name based on whether which key is double tapped. The function was just to make an easy way to change the string into a clip ID, then play it. What's the error with my code that's causing this?