I've just started implementing some animations into my game. I'm trying to choose animations depending on what the player is doing. Problem is, if, for example, "jump" is already playing, setting jump animation to true just resets the animation. How can I check if a specific animation is playing so that I can avoid calling it again?
if (!grounded)
{
skeleAnim.state.SetAnimation(0, "jump", true);
var trackEntry = skeleAnim.state.GetCurrent(0);
trackEntry.TimeScale = 1;
}else
{
if(myRigidbody2D.velocity.x == 0)
{
skeleAnim.state.SetAnimation(0, "idle", true);
var trackEntry = skeleAnim.state.GetCurrent(0);
trackEntry.TimeScale = 0.5f;
}
else
{
skeleAnim.state.SetAnimation(0, "run", true);
var trackEntry = skeleAnim.state.GetCurrent(0);
trackEntry.TimeScale = 3.5f;
}
}
18 Nov 2016 7:25 am
So I've solved my issue. Now I'm using this line to check if the animation is running:
if (skeleAnim.state.GetCurrent(0).ToString() != "jump")
I've got two more follow up questions:
Is there a better way of checking GetCurrent(0) without using .ToString()?
How can I switch animations in a way that makes the blend speed faster?