Sitemap

Extend door functionality using the Interface.

3 min readJul 11, 2025

Objective: Extend door functionality using the Interface.

Before doing anything, when the game starts, we want this door to be locked by default, then we will allowthe player to unlock it using the terminal.

Please review the first article before this if you find this article while you browse in the internet.

Link here https://medium.com/@suleimanabdullah/creating-a-door-interactable-using-the-interface-in-unity3d-90fd24785446

In the first step add Interactable and Door script to this door, but set _isLocked variable to true in the inspector.

Press enter or click to view image in full size

Create a new script called Terminal, then attach it to the terminal, then add Interactable and sphere collider to the terminal, the option of isTrigger in the sphere collider must be true.

Press enter or click to view image in full size

Make sure the terminal inherits IInteractable, then create these two variables.

Press enter or click to view image in full size

Go back to the Door script Inside Activate method, this method will be responsible for setting the door state from locked to unlocked. We do this by setting _isLocked variable to false.

Now we need to access the door through the terminal. We do this using an array of targets. This target will lock to the door assigned to this terminal and will set the status of the door to unlocked.

How do we do this?

We do this by looping through the array of targets, then we get the IInteractable of that door using a handle of IInteractable, then we call Interact.

Note: I have used tryGetComponent to avoid error when this component is not there.

Press enter or click to view image in full size

Select the Terminal and drag and drop our door to the target variable in the inspector.

Press enter or click to view image in full size

This is how we extend our door using the Interface.

Press enter or click to view image in full size

See you in 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

Responses (1)