2D Toolkit Forum
2D Toolkit => Support => Topic started by: peterbrinson on June 27, 2013, 07:33:42 pm
-
I play my animations happily with
anim.Play(theAnim);
...where 'theAnim' is a string I concatenate from a few different variables. If 'theAnim' turns out not to be a proper animation, it breaks the game. So yes, I agree that I should fix any such mistakes.
But I want to make game breaking bugs impossible, so is there a way to check on the animation before I play it, like:
if(--check 'theAnim' exists---){
anim.Play(theAnim);
}else{
anim.Play("dummySprite");
}
-
See if animation is playing: http://answers.unity3d.com/questions/14599/check-if-a-spesific-animation-is-playing.html
If you just want to make sure "theAnim" is not null, then:
if(theAnim){
anim.Play(theAnim);
}else{
anim.Play("dummySprite");
}
It's the same as saying
if(theAnim != null){
anim.Play(theAnim);
}else{
anim.Play("dummySprite");
}
-
'theAnim' is just a string. But you made me realize that something like this works fine
if(anim.GetClipByName(theAnim) != null)
anim.Play(theAnim);
thanks
-
@ peterbrinson that is the right way to do it. You can optimize it a tiny bit further by doing this:
tk2dSpriteAnimationClip clip = anim.GetClipByName( theAnim );
if (clip != null)
anim.Play( clip );