liubohong

If you use timescale = 0, how do you stop the animation and start the run on the same point again
liubohong
  • Сообщения: 2

Harald

I am not sure I understand your question correctly.
In general you can set timescale = 0 and back to 1 to continue playback where you just stopped. You can also query and store playback time via TrackEntry.TrackTime.

In Unity the following code implements what is described above:
using System.Collections;
using UnityEngine;
using Spine.Unity;

public class AnimationStateTesting : MonoBehaviour
{
IEnumerator Start() {
SkeletonAnimation skeletonAnimation = this.GetComponent<SkeletonAnimation>();
yield return new WaitForSeconds(1);

// Pauses playback
skeletonAnimation.AnimationState.TimeScale = 0;
float savedTrackTime01 = skeletonAnimation.AnimationState.Tracks.Items[0].TrackTime;
yield return new WaitForSeconds(1);

// Resumes playback
skeletonAnimation.AnimationState.TimeScale = 1;
yield return new WaitForSeconds(1);

// Sets playback position of first track to saved pause position.
// Note that this is a simple version for only a single track, which also does not
// respect if a different animation is already playing.
skeletonAnimation.AnimationState.Tracks.Items[0].TrackTime = savedTrackTime01;
}
}
Аватара пользователя
Harald

Harri
  • Сообщения: 2438


Вернуться в 中国Spine用户