Recap: Interact Key
Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 10 of 64.
Challenge
EasyGive the player an interact key; Interactor is ready.
- Declare
public interface IInteractablewithvoid Interact();, and make Door, Chest and Lever implement it. Door: turns 90 degrees around y, loggingDoor opened, then back,Door closed.Chest:Found 5 coins, thenThe chest is empty.Lever: switchesbridgeon or off and logsLever pulled.
Press Play and use everything. Then Check.
Try it yourself
using UnityEngine;
public class Door : MonoBehaviour
{
}
All lessons in Game Architecture in Unity
1Components, Not Hierarchies
Small ComponentsA Base Enemy ScriptAbstract ComponentsComponents Working TogetherRecap: Modular TurretRecap: Twin Cannon4Serialized Data
Serializable ClassesLists in the InspectorEnums in the InspectorRecap: Loot TableRecap: Roll the Loot2Interfaces in Unity
IDamageableInterfaces and TryGetComponentGetComponentsRecap: Interact KeyRecap: Nearest in ReachPractice on your own: Unity playground