Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to manage Timeline?

Discussion in 'Timeline' started by aaronghosh14A, Sep 15, 2020.

  1. aaronghosh14A

    aaronghosh14A

    Joined:
    Nov 9, 2019
    Posts:
    13
    Hello guys can anybody please tell me how to play a timeline through script and give it a condition after which it will play?
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Turn off 'play on Awake' on the PlayableDirector. Then, have a script something along the lines of the following:

    Code (CSharp):
    1.  
    2. public class MyBehaviour : MonoBehaviour
    3. {
    4.     public PlayableDirector playableDirector;
    5.     public bool conditionMet {get;set;}
    6.    
    7.     void Update()
    8.     {
    9.         if (conditionMet && playableDirector != null)
    10.         {
    11.             conditionMet = false;
    12.             playableDirector.Play();
    13.    
    14.         }
    15.     }
    16. }
    There are of course many variations - how the condition is met, the playableDirector might be on the same gameObject as this script - but hopefully this gives the general idea.
     
  3. aaronghosh14A

    aaronghosh14A

    Joined:
    Nov 9, 2019
    Posts:
    13
    Thank you so much