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: the first use turns it 90 degrees around y and logsDoor opened; the next use turns it back and logsDoor closed.Chest: the first use logsFound 5 coins; every later use logsThe 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