Set Up & Trigger A Timeline Sequence In Unity
Here’s a quick guide on how to create a new Timeline sequence in Unity, then trigger it via a Trigger Collider.
Today’s Objective: Create a new Timeline asset and trigger it’s playing via a Trigger collider when the player walks through.
Open the Timeline window:
Select the scene GameObject you want to be the Director of the Timeline, then click “Create” in the Timeline window.
Save the “.playable” asset somewhere in your project files. Then with that GameObject selected, you can see the timeline in the Timeline window.
You can add many types of events here, which will happen at that time in the sequence.
Creating the Trigger:
Create a new Box GameObject (or any shape). By default, it will have a Collider attached. Set the “Is Trigger” boolean to true:
Add a Rigidbody to make collisions be detected (not needed if the other colliding object/player already has a Rigidbody).
Creating the collision detection script:
As with all code, there are many different ways to get this functionality working, so you don’t have to specifically write what I have.
The code can be as simple at the above.
However, I personally (and on this occasion) am using UnityEvents and a reusable multi-purpose script to achieve the result:
This allows me to define and modify the actions which will happen when the trigger is collided with very easily, and without modifying the code.