Animate GameObjects using Timeline
I have already written a small introduction to the Timeline of Unity today I will explain how I used it for my cutscenes.
With the Timeline, we can define behaviors of game objects in the scene without having to write a line of code. We can directly access animations, create camera movements as if we were using traditional editing software.
Moving a Game Object
In this first case, we move one of our Virtual Cameras to create a transition.
We can directly insert the clip of the animation on which we are working and this allows us to be well synchronized with the times and not having to go every time in Play Mode to see the results.
To move a game object we must select “+” and select “Animation Track” we will have a new line where we should assign a game object, at the time of its assignment we will be asked, if missing to add an Animator Component to our object.
Now let’s activate recording mode and move the object in question. We will immediately notice that a dot will appear on the timeline of our object. That is a keyframe that will be generated at the moment we make a modification on the game object, at the precise second or frame on which our timeline is positioned.
When we have finished generating the keyframes we just have to stop the recording mode and click on play to see the result.
Basically, we created a camera movement between two points at a specific time.
Fade-in / Fade-out
besides moving the transform of a game object we can create keyframes also when we modify other parameters. For example, an image initially black, to which we are going to modify its alpha, basically a fade-in.
In case we want to modify the keyframes it is not necessary to delete them and repeat the operation entirely. Because we have added an Animator component that allows us through the “Animation Tab” to modify the timing of our keyframes.
Activate/Deactivate a Game Object
The last thing is the activation and deactivation of a game object in the scene.
With the Timeline, we can also do this. We have to add a new element to the Timeline, “Activation Track” I would say that already from the name is quite clear, it allows us to define when the assigned game object should be active in the scene or when it should be deactivated, as in my case.