Sitemap

Creating a puzzle for accessing the Elevator.

4 min readAug 6, 2025

In the first step, create a script called PowerCore and create these variables.

Press enter or click to view image in full size

We want this Object to interact with the player. To do this, we use the Interact method, which is inherited from IInteractable.

Go Inside Interactable and check if _isPickedUp is false and set isKinematic to false, set _isPickedUp to true, then set the PowerCore position and Rotation and parent to _playerPickupTransform.

When the player presses E again, we want to drop this power core. To do this, we set isKinematic and _isPickedUp to false and reset the position to the world. We just set the PowerCore parent to null.

Press enter or click to view image in full size

Create a script called PowerBase with a public virtual OnCollisionEnter function. Use the Collision parameter to set the PowerCore's position and rotation to match the Base position and rotation.

Press enter or click to view image in full size

Create a script called PowerLevel which inherits Scriptable Object, with a public int variable called amount. Then create a public method with a collision parameter, then use that parameter to get the PowerCore component, then increment the powerlevel from the PowerCore by the amount.

Press enter or click to view image in full size

Go to PowerCore variable, create a public method called Change Color, then change color according to this percentage.

Create PowerCharger script, inherit the PowerBase, create PowerLevel variable.

Press enter or click to view image in full size

Create a New script called PowerReceiver, with the following variables.

Press enter or click to view image in full size

Then override OnCollisionEnter, after calling base.OnCollisionEnter, check if we collide with PowerCore, then get the power level from PowerCore.

Check if powerCoreValue(from powerCore) is equal to requiredPowerLevel, then set isActivated to true. Loop through targets, then try to get IInteractable, then call the Interact method and pass isActivated as a parameter to power up the elevator.

Press enter or click to view image in full size

Add an else if and an if statement after the above if to check if the powerCoreLevel is above requiredPowerLevel or below the requiredPowerLevel

Press enter or click to view image in full size

Now override OnCollisionExit by just setting isActivated to false when the PowerCore gameObject is removed from the powerReceiver.This will make the elevator to be malfunction.

Press enter or click to view image in full size

Go to the Project folder <Scriptable Objects create three or 4 powerLevel and specify the value.

Press enter or click to view image in full size
To create scriptable Object just right click and click the top name the name you specify in the code.

Select PowerCore and drag and drop the PowerReceiver to the field called target.

Select the powerCharger add charger script, then drag and drop different scriptable objects to the field name powerLevel.

Press enter or click to view image in full size

Go to the PowerCore < ChangeColor>. We use the safety guide to change color.

Press enter or click to view image in full size

Now let's try our puzzle to see the color change, and how the receiver accepts the powerCore by checking the powerCoreLevel.

Note: You may find an Issue where the camera tries to avoid colliding with the powerCore.By default Main camera is set to avoid collisions with all objects with a physics layer tagged as default.

Solution.

Set the PowerCore object physics layer as Physics Layer or any other layer you specify according to you.

Here it's our puzzle

Press enter or click to view image in full size
Press enter or click to view image in full size

See you at the next one.

--

--

Suleiman Abdullah
Suleiman Abdullah

Written by Suleiman Abdullah

My name is Suleiman Abdullah. I learn game development and share what I learn by writing articles. :https://ko-fi.com/suleimanabdullah

No responses yet