SOVEREIGN MOON PRESENTS…
Using Counters & Switches Within Unity’s 3D Game Kit
In this tutorial we’re going to learn how to use switches and counters to help us make our Unity 3D Game Kit video game more interesting.
Learn how to use Counters & Switches Within Unity’s 3D Game Kit
Yesterday, Sovereign Moon Studios, the makers of your favorite NoCode game development course, taught you how to add dialogue boxes to your game. Today, we will continue our 3D game kit tutorial series by teaching you how to add counters and switches into your game.
Let’s jump in!
What we’re going to be doing in this tutorial is adding multiple switches into our game and then using those switches to open a small door once all of the switches are activated. This can help you improve your gameplay by forcing your characters to go on treasure hunts or fetch quests. Essentially, your characters will be prohibited from passing to the next level in your game until all of the items are found.
So let me show you how this works.
Begin By Adding Your Objects into Your Scene
To begin we need to add our switches and our counter into our game. All of these objects can be found under your project tab in your interactibles folder (which is contained within your prefabs folder). For this purpose of this demonstration we’re going to be adding the following into the scene
1. One small door (interactible)
2. Two switches (interactible)
3. One counter (interactible)
Once we’ve added those items into the scene, our game world will look something like this.
After we’ve done this, we need to scroll down a bit and change our interaction type to “open” under the set game command script.
Next, we need to select our switches so the switch inspector box opens up. We’ll do one at a time, but the changes we make to each one will be identical. With the first switch selected, change the interaction type from “activate” to “open”.
Next, you need to set the interactive object. To do this, simply go to your inspector tab and search for your counter. Your counter should be under your “gameplay” section in your hierarchy tab. When you find the counter, simply drag and drop it into the interactive object section of your switch.
Again, ensure that “one shot” is selected and ensure that layers is set to “player”.
Now, all you need to do is follow these exact same steps for your second switch. Simply select your second switch and copy the settings from your first switch.
Now, within Unity you’ll notice that 3D Game Kit’s visual programing tools have drawn a white line between your switches and your counter. This helps show you that you’ve successfully made a connection between these objects.
Now We Need To Link the Counter to the Door
For the last step, all we need to do is link the counter to the door. To do this, select your counter from the scene tab or hierarchy window. Once the counter’s settings are visible in the inspector tab you’ll need to scroll down until you get to the send game command (script) section. Here, we’ve already set the interaction type to “open”, but we haven’t selected the interactive object yet.
In this example, we want the small door to open once both switches are activated, so let’s go over to our hierarchy section, search for our small door and then drag and drop that object into our interactive object section.
Again, once we’ve completed this step, Unity will draw a white line between our counter and our door.
Let’s Play the Game and Test it Out
At this point, all of the steps are complete and our game should work. So hit play on your game and test it out. As you can see in my video tutorial above, when I activate one switch nothing happens. However, when I activate the second switch the door opens and my player can pass through.
In this tutorial we explored one thing that you can do with counters and switches. You can do a lot more with these tools then we cover in this tutorial. However, if you’re interested in this type of game logic, you might be interested in viewing a recent tutorial we published on how to use Bolt (a free visual scripting tool) to help you add more complex triggers to your game world. This will help you gain more granular control over your game’s mechanics.
Lastly remember, if you’re looking for more in-depth instructions on what you can do with counters, switches and triggers, then I highly suggest you enroll in our comprehensive no-code game development course. We go into much more detail in that course and we teach you how to take your no-code game development skills to the next level. Simply visit our homepage to learn more.
Sovereign Moon Studios is dedicated to helping game enthusiasts bring their creative visions to life without having to know how to code or draw. Our NoCode game development course teaches indie game devs how to build breathtaking games from scratch.
Want to Make Video Games?
Do you love game design? So do we! For this reason, we created a no-code video game development course that walks you through the process of bringing your game visions to life without needing to know how to program and without having to be an artist. We will teach you how to bring your game to life in our 4 hour 36 module no-code game development course.