Unity Timeline动画倒播代码

it2024-12-11  17

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.Playables;  // Timeline相關

 

public class TimelineTool : MonoBehaviour{

    //放入帶有Playable Director的物件(Director用"Hold"模式)

    public PlayableDirector Director;

    void Update(){

        if (Input.GetKeyDown(KeyCode.A)){

            Director.Pause(); //先 Pause();

            StartCoroutine("tRewind"); //倒播

        } 

    }

    //倒播 ================================================================

    public IEnumerator tRewind(){

        yield return new WaitForSeconds(0.001f * Time.deltaTime);

        Director.time -= 1.0f * Time.deltaTime;  //1.0f是倒帶速度

        Director.Evaluate();

        if (Director.time < 0f){

            Director.time = 0f;

            Director.Evaluate();

        }

        else {            

            StartCoroutine("tRewind");

        }

    }

}

最新回复(0)