2019-12-03【Timeline|转自群友】Playable倒放

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"); //倒帶
        } 
    }
 
 
    //倒帶 ================================================================ 3
    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");
        }
    }

你可能感兴趣的:(2019-12-03【Timeline|转自群友】Playable倒放)