- Edited
How to get animation time?
Hey guys,
Someone knows how do i get that info from the spine character?
To do things like ,
if (when in animation X && over frame 3) {
do something
}
or
if ( animation time < 3){
do something
}
I believe is a easy thing, but i am new in c#, i be happy with some help.
Thanks
If skeletonAnimation
is your SkeletonAnimation component.
You can get the currently playing animation through skeletonAnimation.state.GetCurrent(0).Animation
. 0 is the default track number.
Time is always expressed in seconds, not frames. So whatever frame you want, you need to convert it to seconds by dividing it by 30.
You can get the current time through skeletonAnimation.state.GetCurrent(0).Time
. It will return the number of seconds the current animation has been playing.
Note that skeletonAnimation.state.GetCurrent(0)
actually returns a TrackEntry
object. And if you don't have an animation playing, it will return null. So using .Time
or .Animation
immediately will cause it to immediately throw NullReferenceExceptions. Make sure you check for null first.
skeletonAnimation.state is the Spine.AnimationState
. This object manages animations and mixing and playing back. It manages playing multiple animations at the same time which is why it uses TrackEntry
s which you have to get to gain access to the "currently playing animation" or "current time"
Good luck learning C#.
Thanks Pharan, i ll take a look in it today!
But i am using SkeletonAnimator script.
This is how i get the AnimatorState
MecanimAnimations.GetCurrentAnimatorStateInfo (0).IsName ("name of the animation")