My journey becoming a Unity game developer: Security Cameras-Activating the Game Over Cutscene
Objective: Activate the game over cutscene when the player collides with the camera’s light collider. Also, hide the Darren game object from appearing in the cutscene showing us 2 Darren’s instead of one.
When the security cameras lights shine on Darren, we want to trigger the game over cutscene. Create a new script name Security Camera. Create a new variable name gameOverCutscene that will hold the Game Over Cutscene game object. Then use the OnTriggerEnter() function to find out IF the other game object the lights collide with is the Player object. If so, set the gameOverCutscene to be active.
Attach this script to both Camera Cone game objects inside of the 2 Camera_1 objects. The Camera Cone objects represents the lights coming out from the security cameras. Make sure the Mesh Collider’s Is Trigger is turned on to allow the Player object to walk into the lights.
One other thing, attach Rigidbodies to both Camera Cone game objects to allow the Player object to be recognized by the cameras colliders. Also, turn off the Use Gravity setting as well.
As we play the game, when the player is caught by the lights, the cutscene is activated. However, as the cutscene plays we will notice that a 2nd Darren is in the scene. The Player object is still active in the game even though we’re watching the cutscene.
To fix this quickly, open the Timeline editor using the Game Over Cutscene game object. Create a new Activation Track and drag the Player game object into its slot. Place the timeline pointer at the end of the Active track’s position, and drag the beginning of the track’s position to the end where the pointer is located.
Play the game now and see Darren captured when he walks into the lights, and the cutscene plays without the original Darren Player game object appearing in the cutscene.
Next time we will change the color of the lights when Darren is caught.