Unity Spine动画如何选定帧数(时间)播放

  1. 引入Spine.Unity
  2. public SkeletonAnimation ani;
  3. 首先把timeScale设为0,相当于暂停动画ani.timeScale = 0;
  4. 如果需要循环从某一帧播放,可将loop设置为true;
  5. 从对应轨道获取动画var repeat=ani.AnimationState.GetCurrent(0);
  6. 设置目标开始时间repeat.AnimationStart = 3.5f;
  7. 设置目标结束时间repeat.AnimationEnd = 3.5f;
  8. 上方单位为秒。如果需要设置特定帧数,可设为=帧数f/30f;spine默认30帧1秒。
  9. 最后将播放速度设置为1,动画开始播放ani.timeScale = 1;
    10.代码如下:
using Spine.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Setframe : MonoBehaviour
{
    public SkeletonAnimation ani;
    // Start is called before the first frame update
    void Start()
    {
        ani.timeScale = 0;
        var repeat=ani.AnimationState.GetCurrent(0);
        repeat.AnimationStart = 2f;
        repeat.AnimationEnd = 4f;
        caranimation.timeScale = 1;
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}

你可能感兴趣的:(Unity Spine动画如何选定帧数(时间)播放)