My journey becoming a Unity game developer: Game Manager: Win Cutscene Activated

Rhett Haynes
6 min readNov 22, 2021

--

Objective: Create a Game Manager using the Singleton pattern to activate the Level Complete Cutscene when the player reaches the escape door.

Level Complete Cutscene plays when the player reaches its final destination.

To create our Game Manager which will control the state of the game, we will use the Singleton pattern. In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one “single” instance. This is useful when exactly one object is needed to coordinate actions across the system. https://en.wikipedia.org/wiki/Singleton_pattern

The Singleton pattern is best used for games in a Manager class where there will only be one of them such as a Game Manger, Audio Manager, UI Manager, or something of that nature.

To begin, let’s create an Empty game object name Game Manager, set its Transform positions to zero, and attach a new script name GameManager to it. In the GameManager script, we need to create a Static variable to access this class.

Normally we wouldn’t create a variable to be Static because the variable will be located permanently in memory for the lifetime of the program. This means the static variable can be shared within the class if it’s Private, but can be accessible outside of the class and shared if it’s Public. While Non-Static variables are not shared, but Public variables are accessible.

We will name the static variable instance with the Type as GameManager. With this variable we’re going to make not only the variable placed in memory indefinitely, but we’re also going to place the GameManager class in memory indefinitely to allow this class to be accessible. The variable will be assigned Private to keep the variable from being reassigned a value to this instance.

To access this variable, we’re going to create a Property that will be Static with a Type GameManager name Instance. We want to check IF this game object hosting this script is not equal to NULL so we know if the game object was deleted or there is nothing in the scene for it using the DEBUG.LOGERROR function. If the instance is not NULL, then return the instance variable.

Now the instance variable will get assigned when the game is loading in the Awake() function with This script. Also, we will create another property name HasCard with a Type Bool that will have a Getter and a Setter.

Go to the GrabKeycardActivate script, and normally when we want to access the Game Manager script we would use the GameObject.Find(“Game Manager”).GetComponent<GameManager>() approach to getting the GameManager script component. Then set HasCard to True.

The other way using the Instance property, we can use GameManager.Instance.HasCard and set it to True which is an easier way of accessing the HasCard property.

Properties are made for Managers, but the downside of using properties is that it will not show by default in the Inspector. To see the HasCard property in the Inspector, you must use the Debug setting from the hamburger menu.

Click on the Win Cut Scene Zone game object inside the Level Colliders object. Turn on Is Trigger in the Box Collider component, and add a Rigidbody with Use Gravity turned off to allow the player to walk through the collider.

Win Cutscene Zone has a rigidbody added with Is Trigger turned on for the box collider.

Create another new script name WinStateActivation to check IF the Player enters the Win Cut Scene Zone collider. If the player does, check if the player has the card and if the player does, set the winCutscene to be Active. If the player doesn’t have the key card, use the Debug.Log to send a message saying “You must grab the key card.” to let the player know they need to get the key card to move on.

Select the Win Cut Scene Zone game object and attach the WinStateActivation script to it. Drag the Level Complete Cutscene game object into the Win Cutscene slot of the Win State Activation script component.

The Level Complete Cutscene will not play when the player collides with the Win Cut Scene Zone object’s collider. This is happening because the Sleeping Guard Cutscene in Cutscenes is blocking out all of the cutscenes from playing. We used the Cutscenes game object in the Timeline editor as an Activation Track to control the Sleeping Guard Cutscene.

Win Cut Scene Zone not activating because the Sleeping Guard Cutscene inside of Cutscenes in Timeline is overriding it.

Create a new Empty game object name Sleeping Guard Cutscene Holder which will hold the Sleeping Guard Cutscene game object inside of it. Set its Transform positions to zero and drag the Sleeping Guard Cutscene object inside of it. With the Sleeping Guard Cutscene object selected, go back into the Timeline editor. The Activation Track with Cutscenes in its slot, replace it with the Sleeping Guard Cutscene Holder object as this container will now control the Sleeping Guard Cutscene.

Sleeping Guard Cutscene Holder game object created to hold the Sleeping Guard Cutscene itself in it to play the cutscene in the Timeline track.

When we play the game now, we will see the Sleeping Guard Cutscene play when the player reaches the guard’s desk. Then after that cutscene, when the player reaches the doorway at the top of the steps, we will see the Level Complete Cutscene play with the actual player character in the cutscene.

Level Complete Cutscene is playing, but with the actual player included in the cutscene.

To remove the Player from the cutscene, select the Level Complete Cutscene game object. Open its Playable Director in the Timeline editor and create a new Activation Track. Place the Player game object into its slot, and drag the end of the activation clip to the end of the duration’s shot. Set the clip to appear one frame from the end of the duration.

Activation Track created for the Player object to appear one frame before the end of the cutscene’s shot under the Leve Complete Cutscene Playable Director.

Play the game now and see only one Darren in the Level Complete Cutscene acting.

Level Complete Cutscene playing with only the one Darren acting in the scene.

Next time we will create an Audio Manager for this game.

--

--

Rhett Haynes
Rhett Haynes

Written by Rhett Haynes

Learning to become a Unity game developer.

No responses yet