Menu
CoddyTech

Recap: Interact Key

Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 10 of 64.

challenge icon

Challenge

Easy

Give the player an interact key; Interactor is ready.

  1. Declare public interface IInteractable with void Interact();, and make Door, Chest and Lever implement it.
  2. Door: the first use turns it 90 degrees around y and logs Door opened; the next use turns it back and logs Door closed.
  3. Chest: the first use logs Found 5 coins; every later use logs The chest is empty.
  4. Lever: switches bridge on or off and logs Lever pulled.

Press Play and use everything. Then Check.

Try it yourself

using UnityEngine;

public class Door : MonoBehaviour
{
}

All lessons in Game Architecture in Unity

Practice on your own: Unity playground