Here is a test example of my code.
private void FixedUpdate() {
if (idle == true) SetAnimation(IdleAnimation, true, 1 f);
if (run == true) SetAnimation(RunAnimation, true, 1 f);
}
private string currentAnimation;
private TrackEntry currentTrackEntry;
public void SetAnimation(AnimationReferenceAsset animation, bool loop, float timeScale) {
if (animation.name.Equals(currentAnimation)) return;
currentTrackEntry = skeletonAnimation.state.SetAnimation(0, animation, loop);
currentTrackEntry.TimeScale = timeScale;
currentAnimation = animation.name;
}
This code sets the animation.
The fixed update method checks the player's state every frame and if the player is waiting, sets the waiting animation.
And if the player is running - a running animation.
As you can see from the code, if in the current frame the name of the previous animation matches the one being set, we do not restart the animation, which is obvious.
Is it possible to somehow get the number of the current animation frame?
I need exactly the frame number, as in the editor.