- Home /
how do you get the PlayableDirector component in unity c#
I've been looking around for the answer to the same question and I can't find anything. The docs aren't very helpful without code examples. I've tried something like GetComponent<PlayableDirector>() on the gameobject but it keeps saying "PlayableDirector" is not part of the current context. How can I get this component and detect if the timeline has finished playing the cutscene?
On the first part you need a reference to the Namespace either with using UnityEngine.Playable or where ever you access it with UnityEngine.Playables.PlayableDirector. I am not familiar with the Component though so can't help with the second part.
Cheers!
Answer by LiamofElites · Jan 09, 2018 at 10:26 PM
After watching one of the timeline scripting video's, the way to access a PlayableDirector component in a gameobject is to use the UnityEngine.Playable library. So to check if the timeline is playing I'd have to do the following:
 using System.Collections;
 using UnityEngine;
 using UnityEngine.Playable;
 
 public class cutscene1 : MonoBehavior{
     
     PlayableDirector director;
 
     bool playing = false;
 
     void Awake(){
         director = GameObject.Find("cutscene1GameObject").GetComponent<PlayableDirector>();
     }
 
     void Update(){
         if(director.state != PlayState.Playing){
             playing = false;
         }else{
            playing = true;
         }
     }
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                