how i can start timeline on trigger enter for on game cinematic
I took a screenshot from a presentation. Here is an example (see image).
thanks thats really helpful
Here’s the simple example script in text form so you don’t have to type it in
using UnityEngine;
using UnityEngine.Playables;
public class GenericTrigger : MonoBehaviour
{
public PlayableDirector timeline;
// Use this for initialization
void Start()
{
timeline = GetComponent<PlayableDirector>();
}
void OnTriggerExit(Collider c)
{
if (c.gameObject.tag == "Player")
{
timeline.Stop();
}
}
void OnTriggerEnter(Collider c)
{
if (c.gameObject.tag == "Player")
{
timeline.Play();
}
}
}
Recognized your own presentation script?
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
Just change Collider to Collider2D in 15 & 23 line.
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();
}
void OnTriggerExit (Collider2D)
{
if (c.gameObject.tag == “Player”)
{
timeline.Stop();
}
}
void OnTriggerEnter (Collider2D)
{
if (c.gameObject.tag == “Player”)
{
timeline.Play();
}
}
}
using UnityEngine;
using UnityEngine.Playables;
public class OntriggerTimeline : MonoBehaviour {
public PlayableDirector timeline;
// Use this for initialization
void Start()
{
timeline = GetComponent<PlayableDirector>();
}
void OnTriggerExit (Collider2D c)
{
if (c.gameObject.tag == "Player")
{
timeline.Stop();
}
}
void OnTriggerEnter (Collider2D c)
{
if (c.gameObject.tag == "Player")
{
timeline.Play();
}
}
}
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
If we get this working it will be known as the jacob effect!
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.
eff all that…use a prox trigger!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
public class MotorStart : MonoBehaviour
{
public GameObject Motor;
private void OnTriggerEnter(Collider other)
{
PlayableDirector pd = Motor.GetComponent<PlayableDirector>();
if (pd != null)
{
pd.Play();
}
}
private void OnTriggerExit(Collider other)
{
PlayableDirector pd = Motor.GetComponent<PlayableDirector>();
{
if (pd != null)
{
pd.Stop();
pd.time = 0f;
pd.initialTime = 0f;
pd.Evaluate();
}
}
}
}
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
thanks for your help
I`ve used the script shown by mikew unity, but the timelline starts before the player reaches it.
This is months old but in case anyone comes across this: you probably forgot to uncheck Play On Awake on the Playable Director.
Damn Xenophobic. That if statement really did the trick! For some reason the original answer worked, but kept setting my PlayableDirector to “None”.