Extend door functionality using the Interface.
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.
In the first step add Interactable and Door script to this door, but set _isLocked variable to true in the inspector.
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.
Make sure the terminal inherits IInteractable, then create these two variables.
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.
Select the Terminal and drag and drop our door to the target variable in the inspector.
This is how we extend our door using the Interface.
See you in the next one.
