Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

how start timeline on trigger enter

Discussion in 'Timeline' started by dragonstar, Jul 18, 2017.

  1. dragonstar

    dragonstar

    Joined:
    Sep 27, 2010
    Posts:
    222
    how i can start timeline on trigger enter for on game cinematic
     
    faalbane and AntonioModer like this.
  2. tcmeric

    tcmeric

    Joined:
    Dec 21, 2016
    Posts:
    190
  3. dragonstar

    dragonstar

    Joined:
    Sep 27, 2010
    Posts:
    222
    thanks thats really helpful
     
    tcmeric likes this.
  4. gekidoslayer

    gekidoslayer

    Unity Technologies

    Joined:
    Sep 27, 2016
    Posts:
    134
    Here's the simple example script in text form so you don't have to type it in ;P

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3.  
    4. public class GenericTrigger : MonoBehaviour
    5. {
    6.     public PlayableDirector timeline;
    7.  
    8.     // Use this for initialization
    9.     void Start()
    10.     {
    11.         timeline = GetComponent<PlayableDirector>();
    12.     }
    13.  
    14.  
    15.     void OnTriggerExit(Collider c)
    16.     {
    17.         if (c.gameObject.tag == "Player")
    18.         {
    19.             timeline.Stop();
    20.         }
    21.     }
    22.  
    23.     void OnTriggerEnter(Collider c)
    24.     {
    25.         if (c.gameObject.tag == "Player")
    26.         {
    27.             timeline.Play();
    28.         }
    29.     }
    30. }
     
  5. tcmeric

    tcmeric

    Joined:
    Dec 21, 2016
    Posts:
    190
    Recognized your own presentation script? :)
     
  6. InfiniteDesign8

    InfiniteDesign8

    Joined:
    Aug 22, 2017
    Posts:
    38
    what do I need to change to get this working in 2d? the collider part?
    right now nothing happens :(

    Im using Platformer Pro

    any help would make you a god to me
     
  7. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Just change Collider to Collider2D in 15 & 23 line.
     
    InfiniteDesign8 likes this.
  8. InfiniteDesign8

    InfiniteDesign8

    Joined:
    Aug 22, 2017
    Posts:
    38
    Thanks Jacob but
    OntriggerTimeline.cs(15,31): error CS1001: Unexpected symbol `)', expecting identifier

    strangley there is only 30 lines of code not 31..

    using UnityEngine;
    using UnityEngine.Playables;

    public class OntriggerTimeline : MonoBehaviour
    {
    public PlayableDirector timeline;

    // Use this for initialization
    void Start()
    {
    timeline = GetComponent<PlayableDirector>();
    }


    void OnTriggerExit (Collider2D)
    {
    if (c.gameObject.tag == "Player")
    {
    timeline.Stop();
    }
    }

    void OnTriggerEnter (Collider2D)
    {
    if (c.gameObject.tag == "Player")
    {
    timeline.Play();
    }
    }
    }
     
  9. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3.  
    4. public class OntriggerTimeline : MonoBehaviour {
    5.     public PlayableDirector timeline;
    6.  
    7.     // Use this for initialization
    8.     void Start()
    9.     {
    10.         timeline = GetComponent<PlayableDirector>();
    11.     }
    12.  
    13.  
    14.     void OnTriggerExit (Collider2D c)
    15.     {
    16.         if (c.gameObject.tag == "Player")
    17.         {
    18.             timeline.Stop();
    19.         }
    20.     }
    21.  
    22.     void OnTriggerEnter (Collider2D c)
    23.     {
    24.         if (c.gameObject.tag == "Player")
    25.         {
    26.             timeline.Play();
    27.         }
    28.     }
    29. }
    30.  
     
    InfiniteDesign8 likes this.
  10. InfiniteDesign8

    InfiniteDesign8

    Joined:
    Aug 22, 2017
    Posts:
    38
    Thank Jacob! the code compiles now!!

    I put a box collider 2d and checked trigger..any idea why the guy just stops walking against trigger ? like he cant go in..i thought check marking trigger would change that behaviour :(
     
  11. InfiniteDesign8

    InfiniteDesign8

    Joined:
    Aug 22, 2017
    Posts:
    38
    If we get this working it will be known as the jacob effect!:rolleyes:
     
  12. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    If you checked the trigger option and still can't walk into it, then there's likely another collider component on the GameObject, or on a child of the GameObject.
     
  13. InfiniteDesign8

    InfiniteDesign8

    Joined:
    Aug 22, 2017
    Posts:
    38
    eff all that..use a prox trigger!
     
  14. Xenophobic

    Xenophobic

    Joined:
    Dec 21, 2017
    Posts:
    2
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Playables;
    5.  
    6.  
    7. public class MotorStart : MonoBehaviour
    8. {
    9.     public GameObject Motor;
    10.  
    11.     private void OnTriggerEnter(Collider other)
    12.     {
    13.         PlayableDirector pd = Motor.GetComponent<PlayableDirector>();
    14.         if (pd != null)
    15.         {
    16.             pd.Play();
    17.         }
    18.     }
    19.     private void OnTriggerExit(Collider other)
    20.     {
    21.        PlayableDirector pd = Motor.GetComponent<PlayableDirector>();
    22.        
    23.         {
    24.                  
    25.             if (pd != null)
    26.             {
    27.                
    28.              pd.Stop();
    29.              pd.time = 0f;
    30.              pd.initialTime = 0f;
    31.              pd.Evaluate();
    32.              }
    33.         }
    34.  
    35.         }
    36. }
    I was having a ton of issues getting this to do the exit part and return to the start of the playable-- thankfully -splicing works eventually :) now this works as a simple on enter on exit to run directors!- well at the most basic level
     
    giorgospapastergiou69 and EvOne like this.
  15. dragonstar

    dragonstar

    Joined:
    Sep 27, 2010
    Posts:
    222
    thanks for your help
     
  16. Valentinus777

    Valentinus777

    Joined:
    May 30, 2020
    Posts:
    3
    I`ve used the script shown by mikew unity, but the timelline starts before the player reaches it.
     
  17. ekemini

    ekemini

    Joined:
    Apr 20, 2019
    Posts:
    2
    This is months old but in case anyone comes across this: you probably forgot to uncheck Play On Awake on the Playable Director.
     
    jandolina likes this.
  18. giorgospapastergiou69

    giorgospapastergiou69

    Joined:
    May 21, 2020
    Posts:
    1
    Damn Xenophobic. That if statement really did the trick! For some reason the original answer worked, but kept setting my PlayableDirector to "None".