My journey becoming a Unity game developer: Sleeping Guard Interaction-Activate sleeping guard’s cutscene
Objective: Activate the Sleeping Guard Cutscene when the player reaches the guard’s desk. Also, remove the real Security Guard and Player from the screen when the cutscene is playing.
Create a new script name GrabKeycardActive which we will use to activate the Sleeping Guard Cutscene. Create a new variable Type Game Object that will hold the actual Sleeping Guard Cutscene game object itself. Then using the OnTriggerEnter() function, check IF the other object that collides with the Security Guard’s desk is the Player tag. If so, set the Sleeping Guard Cutscene to Active.
Select the Grab Cut Scene Zone game object which has a Box Collider around the desk. Drag the GrabKeycardActive script onto it, add a Rigidbody component with Use Gravity turned off, and turn on Is Trigger for the Box Collider.
Click on the Sleeping Guard Cutscene game object to gain access to the Timeline editor for this cutscene. Either double-click on the Playable Director slot or select Window->Sequencing->Timeline to open the Timeline editor.
Create a new Activation Track and drag the Sleeping Guard game object into its slot. We want to make the guard disappear during the cutscene playing and bring him back at the last frame before the cutscene ends. Either drag the track from the beginning to the last frame or click on the track, and in the Inspector change the Duration to be separated by one frame, then in the Start setting set the value to be one number in front of the End setting frame value.
Create another new Activation Track and drag the Actors game object inside of the Sleeping Guard Cutscene object which will show the actors from the cutscene in the Scene View. This time we want the Actors to stay onscreen while the cutscene is playing until the last frame, then remove them as the real Sleeping Guard comes back onscreen. Either drag the track back one frame or set the End setting one frame back from the track’s duration.
When we play the game and the player collides with the Security Guard’s desk, we see the cutscene playing. However, there is another problem arising with the player still onscreen in the cutscene.
Create one more Activation Track and drag the Player game object into its slot. Set the Player’s track to reappear one frame before the End frame value.
Now when the player collides with the Guard’s desk, the cutscene will play with the Security Guard and Player game objects disappearing from the cutscene playing. Then see them reappear when the cutscene ends.