Making a Treasure Chest Timeline Animation— Unity3D
2 min readSep 19, 2023
To make a treasure chest system using Timeline, you will need to:
- Create a new Timeline asset.
- Add an Animation Track to the Timeline asset and assign the animation clip for the treasure chest opening animation to the track.
- Add a Particle System Track to the Timeline asset and assign the particle system for the treasure chest opening animation to the track.
- Add an Audio Track to the Timeline asset and assign the sound effect for the treasure chest opening animation to the track.
- Create a new C# script and attach it to the treasure chest GameObject.
- In the script, add a public variable for the Timeline Director.
- Add a OnTriggerEnter() method to the script.
- In the OnTriggerEnter() method, play the Timeline Director.
Here is a simple C# script for the treasure chest system:
using UnityEngine;
using UnityEngine.Playables;
public class TreasureChest : MonoBehaviour
{
public PlayableDirector timelineDirector;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
timelineDirector.Play();
}
}
}
To set up the treasure chest opening animation with a particle system and sound, you will need to:
- Create a new particle system for the treasure chest opening animation.
- Create a new audio clip for the treasure chest opening animation.
- Add the particle system to the Particle System Track in the Timeline asset.
- Add the audio clip to the Audio Track in the Timeline asset.
- Adjust the timing of the particle system and audio clip so that they match the treasure chest opening animation.
Once you have set up the treasure chest opening animation, you can place the treasure chest GameObject in your scene and test it out. When the player enters the trigger collider of the treasure chest, the Timeline Director will play and the treasure chest will open, revealing the loot inside.
Here are some additional tips for creating a treasure chest system using Timeline:
- You can use multiple animation clips in the Timeline asset to create a more complex treasure chest opening animation.
- You can use masks to control which parts of the treasure chest animation are affected by the Timeline Director.
- You can use signal emitters to trigger the Timeline Director from other objects in the scene.