Unity3d 脚本播放Timeline

预制体

在这里插入图片描述

脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;

public class TimeLineDirector : MonoBehaviour
{
    
    
    [SerializeField] 
    private PlayableDirector _director;

    private float _animationTime = 10f;
    
    // Start is called before the first frame update
    void Start()
    {
    
    
        _director.gameObject.SetActive(false);
        _director.Stop();
        _director.initialTime = 0;
        _animationTime = 300 / 60f;
    }

    public void Play()
    {
    
    
        _director.gameObject.SetActive(true);
        _director.initialTime = 0;
        _animationTime = 300 / 60f;
        _director.Play();    
    } 
    
    // Update is called once per frame
    void Update()
    {
    
    
        if (_director.time >= _animationTime)
        {
    
    
            _director.Stop();
            gameObject.SetActive(false);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/WGYHAPPY/article/details/129647527