Create Games with the 3D Game Kit – Part 2

Introduction

This tutorial is the second installment of a series on the amazing 3D Game Kit (click here for the first one). Part 1 left things soft of on a cliffhanger as we opened up the expansive “Interactables” folder. In this follow up, we will be covering most of the prefabs in this fabulous feature full folder. This includes things like switches, counters, and doors. With this knowledge, you will be able to understand how the 3D Game Kit works behind the scenes, and it will give you the ability to make your games more engaging for the player. Without further ado, let’s continue examining this terrific tool to transform our textured terrains (that was my attempt at alliteration).

Doors and Switches

You will notice in the Interactables folder that there are three different door prefabs.

The differences between these prefabs are mainly in the design and not in the actual function. A door has many uses in a game and that’s why we will focus a lot on these sorts of prefabs. Go ahead and drag one of the prefabs into your scene (doors go under Gameplay) and let’s have a look at what we can do with it.

At first glance, we can see two things that look fairly significant. The first is the “start” and “end” gizmos. These are designed to be self-explanatory when the door is triggered it will move to where ever the “end” transform is. This gives us a couple of design advantages, for example, when the door is triggered it could open up one passage and then simultaneously be moved in front of another passage. So that the player is forced to make careful decisions about where to trigger doors knowing that it will block another potential path. This is just one example of what we could do with this system of opening doors. The second thing that is apparent when we examine this door is the “Game Reciever” component in the inspector.

This is the actual component that does the “behind the scenes” work and it tells us about how the 3D Game Kit deals with its Interactables. The way the 3D Game Kit handles things like doors is through a system of Senders and Receivers. The door is an example of a receiver. In order to be opened, it must obtain a command from a separate game object known as a Sender. A Sender could be a switch, a pressure pad, or even just an inventory that possess all the required items. This system is a fairly common messaging system that has been set up so that we don’t have to program all these reactions. So let’s see what Interactables we can use to open this door. Go ahead and drag the “Switch” prefab somewhere in your scene, this is what will open the door so place it accordingly (this goes under Gameplay as well).

You will notice that the switch has a “Send On Trigger Enter” component.

This is where the data is sent to the receiver. Drag the door game object into the “Interactive Object” field. Change the “Interactive Type” to “Open”.

Notice that the switch and the door are now connected by a line gizmo. If you hit play you’ll notice that we can now open the door through this switch!

Doors and Counters

A switch is a pretty basic way of opening a door. The player crashes into it and the portal flies open. Thankfully, there are two other ways of opening a door with the 3D Game Kit. One of them is mainly design oriented and the other is for gameplay purposes. Let’s look at the aesthetics one first. You may have already noticed the “PressurePad” prefabs in the Interactables folder.

These work the same way as the switch except they’re a little less noticeable. This could be useful if you wanted to make one of them hidden so the player has to search for it. It has the exact same components as the switch so you already know how it works. The other way of opening doors is by using multiple switches. We do this by using the “Counter” prefab in the Interactables folder.

This allows us to add another level of complexity, and therefore entertainment, to opening a door. Go ahead and drag in the Counter prefab and let’s have a look at it (it goes under “Gameplay”).

We recognize the “Send Game Command” component from the switch but there is also another component called “Gameplay Counter”. One thing that is very convenient about the 3D Game Kit is that everything has a nice descriptive title. Such is the case with this component, this is what keeps track of “activated” switches. At first glance, we recognize the “Interaction Type” field along with the standard “Cool Down” and “Start Delay”. But notice that there are two new integer fields named “Current Count” and “Target Count”. This is the legendary descriptive title at work which renders these variables self-explanatory.  “Target Count” is currently set to three so let’s go ahead and drag in three switches (or pressure pads, it works the same way) onto our terrain.

Since the Counter game object is only really visible in the hierarchy, let’s change the size and color of its gizmo so that we can see it.

Now we need to wire these switches together, we do this by selecting a switch and dragging the Counter object into the “Interactive Object” field. Set the “Interactive Type” to “open” and then repeat this across the other two switches.

Next, make sure the both of the “Interactive Type” fields on the Counter are set to “open”. Then drag the door game object into the “Send Game Command” component.

You’ll notice that we have arrows running from each switch to the counter than from the counter to the door. This visual aid will be a huge help if you start adding in more doors with switches. With all of this done we can hit play and open our door by activating each switch!

 

 

Bonus: adding a visual progress

When we add multiple switches into our scene it would be much better to space the switches out all over the level. This is so the player can go and “hunt” for all the switches in order to open the door. Let’s go ahead and place the active switches in different places in our scene.

This really is the reason we use multiple switches so that it is more challenging for the player. But the problem with immediately throwing switches in obscure places is that the player doesn’t know how many switches to look for.

It could be two or twenty-two but the player still wouldn’t know if the switch he just activated was the first of ten or the first of twenty. We need a way to visually indicate to the player the progress of unlocking the door. We do this by having “crystals” next to the door which lights up every time a switch is activated. Go to the Interactables folder and drag three “Crystal” prefabs (one for each switch) on the left side of the door (these crystals go under Gameplay).

Now, all we have to do is to add another “Send On Trigger Enter” component to a switch, then drag a crystal into the “Interactive Object” field.

Make sure that “Interactive Type” is set to “activate”, the Layer is set to “Player”, and that “One Shot” is enabled. Now when you activate this switch in the game, you’ll notice that the crystal lights up as well!

Fantastic! Now just repeat that process for the other two switches and you’re good to go!

Teleporters

A game as complex as this wouldn’t be complete without teleporters. There are two types of teleporters in the 3D Game Kit. The first is your standard “place to place” teleporter where the player is transferred from one place in the scene to another. The other is used to “teleport” the player to another scene. This one can be used as a level completion teleporter. Let’s have a look at the first sort of teleporter.

The “Interpolation” teleporter

Let’s go ahead an drag in a “GateWayHugeTeleporter” (this is in the “Structures” folder), this will serve as our teleporter. Rotate it around so we can see the nice “teleporter” overlay.

Next, open up the “GateWayHugeTeleporter” and find the “TeleportPlane” game object.

This will be the collider that will trigger teleportation so make sure it has a Box Collider that is set to “trigger”.

Click “Add Component” and search “Teleporter”.

Add the “Teleporter” script and let’s wire up this teleporter.

The settings here are pretty straight forward, we need to change the layer to only pick up the player, and we need to set up a destination transform. Let’s do the latter before the former, create an empty game object (this could go under “GameUtilities”) and name it “TeleportDestination”.

Drag this into the respective slot on the “Teleporter” script and we’ll see that the gizmo in the scene view has changed. Next, let’s go ahead and add in a particle effect when the player leaves the teleporter. All we need to do is to expand the Ellen game object and drag the “RespawnParticles” onto the “Exit Effect”.

Now hit play and walk into the DoorGateway. Boom! The teleporter is online!

The “Scene to Scene” teleporter

This next one is a bit more involved. We first off need two scenes, one to teleport from and one to teleport in to. We already have the first one so let’s set up the end scene. Create a new scene in the 3D Game Kit named “Scene2”.

From here go to the “SceneControl” folder and drag in the “TransitionDestination” prefab (this goes under Gameplay).

Here we need to set what is known as a “DestinationTag”, this is just a letter that the teleporter uses to identify the correct destination. Set it to something other than the default because the demo package likely uses the default tag. Next, drag the “Ellen” game object into the “Transitioning Game Object” field and make sure the “On Reach Destination” function call is set to “CharacterStateSetter.SetCharacterState”.

Okay! We’re done with this scene so let’s add it to the build settings. Go to File->Build Settings

and click “Add Open Scenes”.

Now go back to Scene1 and let’s set up the teleporter on this end. Go ahead and place another DoorGateWayHuge in the scene to serve as the new teleporter.

Go to the “SceneControl” folder and drag the “TransitionStart” prefab in the doorway.

Right off the bat, there is something that we must do to this prefab or else it will not work. When I was using this, I noticed that the collider attached to this game object is a 2D collider.

They may update this in the future, but for right now, we need to switch this out with a 3D collider or else the attached script will not work. Add a Box Collider, scale it so that it fits the doorway, and make sure it is set to “Trigger”.

Okay, now drag the “Ellen” game object into the “Transitioning Game Object” field … and set the “Transition Type” to “Different Zone”. Next, set the proper scene (Scene2) and the proper tag. Change it transition “On Trigger Enter” and that should complete our “Scene to Scene” teleporter!

Hit play and beam her up Scotty!

Dialogue boxes

The last thing we are going to look at is the dialogue used in the demo to tell the player how to use the game. I thought this was pretty cool so let’s go ahead and re-create this in our own scene. Let’s have it so that when the player walks up to the locked door, we’ll get a dialogue box that says something like, “Hmm… Looks like I have to find all the switches in order to open this.” To do this, go back to the “Interactables” folder and find the “InfoZone” prefab. Drag it and scale it so that it covers the door very liberally (this goes under GameUtilities).

Next, go to the “UIPrefabs” and drag in the “DialogueCanvas” (this goes under “UI”).

Now, all we have to do is to drag the DialogueCanvas into the two slots in the InfoZone.

Set the layer to only detect the player and set the “On Enter” call to be “DialogueCanvasController.ActivateCanvasWithText” and the “On Exit” to be “DialogueCanvasController.DeactivateCanvasWithDelay”. Now, to finish this, all we do is to type our text in the “On Enter” field and we’re all set up!

Now we have a way of telling the player what is happening.

Conclusion

You probably already know that the 3D Game Kit can do more than I have detailed in the second part of this tutorial series. You would be correct. I suggest acquiring a spirit of exploration in order to understand more about this expansive tool. Unity has decent documentation which you can use as a starting point. I would suggest that you start there, but don’t forget to…

Keep making great games!