10: The Great Escape (Part 3)
Learning Target
- Use a simple C# script to make your escape room react to the player
- Connect an XR Interaction Toolkit event to a script
- Make a button, object, or trigger zone cause something to happen
- Add feedback so the player knows an interaction worked
Resources
Instructions
In this assignment, you will begin adding some simple puzzle logic.
The goal is not to create a complicated game yet. The goal is to make your room react when the player does something.
For example:
- Press a button → light turns on
- Place a key on a table → a door unlocks
- Pick up an object → a message appears
- Put a battery into a machine → a hidden object appears
- Enter an area → a warning message appears
Part 1 – Open and Check Your Project
Step 1: Open Your Existing Project
Open the project you used for the previous escape room assignments.
Before you begin, make a quick backup of your project.
Step 2: Save a New Scene Version
Save your scene with a new name such as:
EscapeRoom_Part3
This helps you keep your changes separated in case something breaks.
Step 3: Check That Your XR Setup Still Works
Run the scene in Play Mode and make sure you can still:
- move around
- look around
- teleport
- aim at interactable objects
- grab at least one object
- select or press at least one object
If your basic VR setup does not work, fix that before moving on.
Part 2 – Plan a Simple Placement Puzzle
Step 1: Choose the Object the Player Will Move
Choose one object the player can already pick up or will be able to pick up.
Good examples:
- key
- battery
- book
- fuse
- gem
- tool
- puzzle piece
- access card
- chemical bottle
- flashlight
This object should have:
- a Collider
- a Rigidbody
- XR Grab Interactable
If the player cannot pick it up yet, fix that before continuing.
Step 2: Choose the Correct Spot
Choose where the object should be placed.
Good examples:
- pedestal
- table
- shelf
- machine
- fuse box
- charging station
- tool bench
- locked panel
- scanner area
- marked floor pad
This spot should be easy for the player to see and reach. It should make sense to the player why the object goes there after they place it (though perhaps not as clear beforehand).
Step 3: Choose What Happens When the Puzzle Is Solved
Choose one simple result.
Good examples:
- a light turns on
- a hidden object appears
- a clue appears
- a door disappears
- a lock changes color
- a warning sign disappears
- an exit marker appears
For this assignment, the easiest result is to make a hidden object appear.
Example plan:
The player will pick up the blue battery and place it on the charging pad. When the battery is placed correctly, a green light will appear.
Another example:
The player will put the gold key on the table. When the key is placed correctly, the exit door will disappear.
Step 4: Write Down Your Puzzle Plan
Create a text file in your Assets folder and write down your plan.
For example:
The player will place ____________________ on/in/near ____________________.
When this happens, ____________________ will appear, disappear, or turn on.
Part 3 – Create the Trigger Zone
Step 1: Create an Empty GameObject
In the Hierarchy, create an empty GameObject.
Name it something clear, such as:
- Battery_Check_Zone
- Key_Check_Zone
- Gem_Pedestal_Zone
- Fuse_Box_Zone
This object will be used to check whether the correct item has been placed in the correct location.
Step 2: Move the Trigger Zone to the Correct Spot
Move the empty GameObject to the location where the player should place the object.
For example:
- just above a table
- inside a fuse box
- on top of a pedestal
- inside a machine
- near a door scanner
Step 3: Add a Box Collider
Select the trigger zone object and add a collider.
Set the collider to be a trigger.
A trigger collider detects that something entered the area, but we can still put an item there. A normal collider would block movement.
Step 5: Resize the Trigger Zone
Resize the Box Collider so it covers the correct placement area.
Make the trigger zone a little larger than the object you plan to place there.
Do not make the trigger zone too small. Otherwise, it will frustrate the player and make testing difficult.

Part 4 – Prepare the Object That Will Be Detected
Step 1: Select the Grabbable Object
Select the object the player will place into the trigger zone.
For example:
- Battery
- Key
- Gem
- Fuse
- Book
Step 2: Test the Grab
The object must have a Collider, Rigidbody and XR Grab Interactable.
Test your game to make sure this is working.
Step 3: Give the Object a Tag
At the top of the Inspector, find the Tag dropdown.

Click Add Tag to create a tag that describes the object.
Examples:
- Key
- Battery
- Gem
- Fuse
- PuzzleObject
Use a simple tag name with no spaces.

For this assignment, your script will check the tag to decide whether the correct object entered the trigger zone.
Then, click on your object again and select the correct tag for your object.

Part 5 – Create Your First Script
Step 1: Open Your Scripts Folder
You should already have a Scripts folder from the previous assignment.
Open the Scripts folder.
Step 2: Create a New C# Script
Right-click in the Scripts folder and find this option:
Create → Scripting → Monobehaviour Script
Name the script based on what it will do:
PlacementPuzzle.cs
Be careful with spelling and capitalization.
Step 3: Open the Script
Double-click the script to open it.
You should see a basic Unity script.
Part 6 – Detect the Object Entering the Trigger
Step 1: Remove Start and Update
This script does not need Start or Update.
Start happens when the game begins.
Update happens every frame.
Our puzzle does not need to check every frame. It only needs to react when something enters the trigger zone.
Delete the Start and Update sections.
Step 2: Add Variables
There are two things we need to know:
- What is the correct tag?
- What object is affected?
You will need a couple variables to store these. For example:
public string requiredTag = "Battery";
public GameObject objectToActivate;
Step 2: Add OnTriggerEnter
Inside the class, add this method:
private void OnTriggerEnter(Collider other)
{
}
This method runs automatically when another collider enters this trigger zone.
Step 3: Check the Object’s Tag
Check the the object entering the trigger zone has the correct tag.
Inside OnTriggerEnter, add an if statement:
if (other.CompareTag(requiredTag))
{
}
Step 4: Activate the Result Object
Inside the if statement, activate the result object:
objectToActivate.SetActive(true);
Step 5: Save the Script
Save the script.
Return to Unity and wait for it to compile.
If you see red errors in the Console, check your script. Common errors are:
- Incorrect or inconsistent names
- Missing semicolons ;
- Incorrectly paired curly braces { }
Use this picture to help you if you are having issues.
Part 7 – Attach and Configure the Script
Step 1: Add the script
Select the trigger zone object you created earlier and add your new script to it.
Step 2: Set Variable Values
In the PlacementPuzzle component, set Required Tag to match the tag on your grabbable object. The spelling must match exactly.
Drag the object that should appear, disappear, turn on or turn off into the Object To Activate field.

Step 3: Set the Result Object to Inactive
If your object will be appearing or turning on:
- Select the object that will appear
- In the Inspector, uncheck the checkbox next to the object’s name.

This makes the object inactive at the start.
When the puzzle is solved, your script will turn it on.
Part 8 - Add a Custom Puzzle Action
Step 1: Choose What Should Happen
So far, your placement puzzle can detect when the correct object is placed in the correct spot.
Now you will create your own action script. Each different type of action should be a separate script.
Good examples:
- open a door
- slide open a drawer
- move a secret panel
- change the material of a lock, button, or screen
- play a sound
- activate the next part of the puzzle
Keep the action simple. The goal is to make one clear thing happen when the puzzle is solved.
Step 2: Create a New Script
Give the script a clear name based on what it does.
Good script names:
- OpenDoor
- SlideObject
- ChangeMaterial
- PlaySound
Avoid vague names like:
- Monobehavior1
- Script1
- ThingHappens
- PuzzleStuff
- Code
- MyScript
The script name and the class name must match exactly.
Step 3: Decide What the Script Needs to Control
Before writing the code, think about what information the script needs.
Example 1: OpenDoorOnPlacment
The script needs to know:
-
- what is the correct tag for a placed object
- which door to rotate
- what rotation should count as open
Example variables:
public string requiredTag = "Key";
public Transform door;
public Vector3 openRotation = new Vector3(0, 90, 0);
Example 2: ChangeMaterialOnPlacement
The script needs to know:
-
- what is the correct tag for a placed object
- which object renderer to change
- which material to change to
Example variables:
public string requiredTag = "Apple";
public Renderer targetRenderer;
public Material newMaterial;
Example 3: SlideObjectOnPlacement
The script needs to know:
-
- what is the correct tag for a placed object
- which object to move
- where the object should move
Example variables:
public string requiredTag = "Hand";
public Transform objectToSlide;
public Vector3 newPosition;
Step 4: Write Code for your Trigger
Each script will can use OnTriggerEnter, or you can add other possible interactions.
This method runs when another collider enters the trigger zone.
The basic pattern for a trigger is this:
private void OnTriggerEnter(Collider other) {
if (other.CompareTag(requiredTag)) {
// Do the action here.
}
}
Possible actions you could do:
door.localEulerAngles = openRotation; // open a door
targetRenderer.material = newMaterial; // change a material
objectToSlide.localPosition = newPosition; // move an object
More to come!
Grading
| Criteria | Letter Grade |
|---|---|
|
Exceptional |
A |
|
Good |
B |
|
Reasonable |
C |
|
Needs Improvement |
D |
|
Insufficient |
F |
| Scores may be rounded to the nearest whole number. | |