Misaki написав
You can use AnimationState getCurrent to get the track entry for the animation currently playing on the track. (It returns null if no animation is currently playing.)
Fortunately, there are an example scene and a C# script to show you how to check the current animation on a specific track and do something depending on that. You can find the scene Spine Examples/Getting Started/5 Basic Platformer
, and SkeletonAnimationHandleExample.cs
which is attached to the Player
GameObject in the scene shows you the example code.
Hey, thanks for the reply.
I didn't want the example scenes to take up space in my project. So I don't have the example scene unfortunately.
I just ended up doing this:
public SkeletonAnimation SpineSkeleton;
private AnimationReferenceAsset currentState;
public AnimationReferenceAsset Idle;
public AnimationReferenceAsset Walk;
// Start is called before the first frame update
void Start()
{
}
public void SetAnimation(AnimationReferenceAsset animation)
{
if (CheckIfAlreadyPlaying(animation))
{
SpineSkeleton.state.SetAnimation(0, animation, true);
}
}
private bool CheckIfAlreadyPlaying(AnimationReferenceAsset animation)
{
if ( currentState != animation)
{
currentState = animation;
return true;
}
else
return false;
}
But I'd like to know how to use it properly anyway. It doesn't look like you can use AnimationState getCurrent to compare it with an AnimationReferenceAsset. If you could provide me an example of how you would use AnimationState getCurrent to see if it's the same as a specific animation, that would be great.
Misaki написавI’m afraid to say but I’m not sure what you mean by that. What is it that you are concerned about?
When will the first parameter in SetAnimation() not be 0? I've just been setting it to 0 every time to play animations.
Thank you!