using UnityEngine; using UnityEngine.Playables; using UnityEngine.Serialization; using UnityEngine.UI; public class IntroCinematicsPlayer : MonoBehaviour { [FormerlySerializedAs("ShouldPlayIntro")] public bool shouldPlayIntro; private Image _introRenderer; private PlayableDirector _director; private Animator _animatorComponent; void OnEnable() { // Get the director and subscribe to when it stops playing _director = GetComponent(); _introRenderer = GetComponent(); _director.stopped += OnPlayableDirectorStopped; _animatorComponent = GetComponent(); } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { //Play the intro and unhide the Canvas object if intro is enabled if (shouldPlayIntro) { _introRenderer.enabled = true; _director.Play(); _animatorComponent.enabled = true; } ; //Disable the intro Canvas object if intro is disabled if (!shouldPlayIntro) { _director.Stop(); _introRenderer.enabled = false; _animatorComponent.enabled = false; } ; } void OnPlayableDirectorStopped(PlayableDirector aDirector) { // Disable the introsequence gameobject when intro is finished playing _introRenderer.enabled = false; } }