This is The Cube, a small puzzle game I’m building for an upcoming session in my D&D campaign. It will have players navigating a 3x3x3 room cube, solving puzzle doors, rotating the cube itself for navigation, and placing magic crystals to get The Cube powered up again.


Overview

Coin Exchange

One of the key puzzles in The Cube is the Coin Exchange. There are a variety of doors that are locked until the player puts in the correct amount of coins. Different coins have different values and it’s up to the player to find their worth by comparing them to each other in the Comparitor. After that they just need to put the correct values in the correct doors.

Cube Rotator

The Cube is ancient, broken down, and partially stuck in a cave wall. As a result, some hallways are blocked off by rock and rubble. The player must unlock doors to navigate around, and to get between floors must use the teleporters. The teleporters teleport the player directly up/down, so to gain access to more areas of The Cube the player must rotate The Cube itself to change the teleporter locations.

Power Crystals

Due to years of neglect, The Cube is in disrepair and barely functional. To power up again the player must collect colored Power Crystals, place them in the proper location (1 for each corner of the cube), then properly orient The Cube itself.

Tools and systems

Tools

UnityEvent Locator

This tool is useful for seeing where all the UnityEvents tied to an object are located. It draws lines from the base object to each object connected from a UnityEvent.


Cameras

For cameras and camera transitions I used cinemachine. Each “section,” where the camera zooms in/move to a specific position, has it’s own virtual camera that gets turned on and off that cinemachine automatically transitions between.


Inventory

There are two different inventories, one for coins and one for items. They work pretty much the same, but have slight differences. The coins, for example, stack while item do no. The coin inventory is also fixed since there are only so many coins, but the item inventory is more dynamic allowing more items, sorts them, it even has a system that automatically makes pictures for them! This did cause a few issues with getting The Hand to work properly, and it probably would have been easier to have them use the same inventory, but when I started I wanted to keep them seperate so I could work on them a little differently since they both serve slightly different purposes.

The Hand

The player has a hand that hold the “active item.” When you click an item it puts it in the players hand, which lets them use it with stuff. Putting items in the hand actually removes them from the inventory, but they get added back if something else gets put in the hand, or the player puts the item back by clicking on it.

Items

Items are objects that can be picked up and stored in the player’s inventory. When the player looks at an item in range, the object gets outlined indicating it can be interacted with.

Item Podium

Items can be placed on the item podium if they are active (in the hand). Items on the podium can be picked up, and if the player is holding something while taking an item from the podium it will swap them. When an item is placed it can send out an event to trigger another script.


Coins

The player gains a variety of coin that get added to their inventory. Each coin has a specific value tied to it which is used for comparing to a door’s value to open it. The coins are displayed on the bottom left of the screen. There are a few componenets to make interaction with coins easier, namely the Coin Slot and Coin Return. The Coin Slot allows other scripts to easily plug into coins the player puts in them. The coin return allows other scripts to easily return the coins that were put into it from the coin slot. Returning the coins enables the appropriate coin models and slides them out of the “machine.” The player must then click on them to put them back in the coin inventory.

Coin Return In Action

Comparitor

This device allows the user to compare values of coins. There are two coin slots, A and B, which can hold as many coins as are put in. Clicking the Compare Button shows if A is Greater Than (>), Equal To (=), Less Than (<), or if one or more of the slots don’t have any coins (X). The player can use the coin return to regain the coins put in the machine

Coin Door

Each coin door will only open when the proper amount of coins has been put in. Each door has a different value need to open it. Trying to open the door with the wrong amount will return all coins put into it


Rotator

This device controls the rotation of the floors of The Cube. While the cube rotates it disables the teleporters, causes a small amount of screen shake, spawns dirt and dust particles from the ceiling, and plays a stone grinding sound to indicate the floors are turning. The rotator interacts with two main things, the smaller cube the player actually interacts with, and the larger actual structure of The Cube. Rotating the smaller pieces rotates the larger pieces, but the larger pieces take much longer to rotate than the smaller ones (about 5 seconds). It basically just uses a Coroutine to slerp between a start and end rotation value.

Elevators

Since the actual position of the floors and teleporters change, it was important to have a dynamic way of linking teleporters. So whenever the teleporters turn active again they check from a list of all other teleporters if there are any that are in relativly the same XZ position, then checks if there are any above or below them from the Y value. Then they check if they are compatible (and Up elevator can only pair with a Down elevator). On thing I wanted to be able to do was offset the floors so I could easily see inside all of them at once for placement and planning, so the XZ position ended up being relative to its parent so I could move the floors wherever and still have the teleporters connect properly.