Eye of the Nile Docs
Everything you need to know to get started!
Loading...
Searching...
No Matches
PlayerInteract Class Reference

Detailed Description

When the player presses the interactKey, this script will search for nearby interactable objects. If an interactable object is within range, this script will tell that object to trigger its functionality. It will also wait to see if the user holds the interact key down for long enough for it to be considered a "long press" and triggers any additional functionality.

Documentation updated 4/6/2025

Author
Stephen Nuttall, Alexander Art

Public Attributes

Transform attackPoint
 Reference to the player's's attack point. It's a point in space that's a child of the player, existing some distance in front of it. Projectiles spawn from the attack point, and melee attacks scan for enemies to damage from a certain radius around it.
 
LayerMask interactableLayers
 List of layers that the player can interact with objects on.
 
float interactRange = 0.5f
 Distance from the attack point an object can be to allow interaction.
 
string interactKey = "e"
 Name of the key the player must press to interact with an object.
 
float interactCooldown = 0.5f
 Cooldown time after an interaction has happened, in seconds.
 
float longPressLength = 1f
 Amount of seconds the user should have to hold the interact button to trigger a long press interaction.
 
List< Collider2D > touchedInteractables
 List of all interactables overlapping with the player's hitbox.
 
Collider2D[] previouslyInRange
 Keep track of which interactables were in range on the previous frame/game loop cycle. Used for triggerProximityEnter/Stay/Exit.
 

Events

static Action< float > interactProgress
 An event that reports the current progress on a long press interaction. Used for InteractProgressBar.
 

Private Member Functions

void Awake ()
 Set reference to dataManager.
 
void Update ()
 Get all interactables currently overlapping with the player's hitbox (OnTriggerEnter() and OnTriggerExit())
 
void OnTriggerEnter2D (Collider2D collision)
 Runs when an object enters the player's hitbox. Adds any newly touched interactables to the touchedInteractables list.

Parameters
collision

 
void OnTriggerExit2D (Collider2D collision)
 Runs when an object exits the player's hitbox. Remove any untouched interactables from the touchedInteractables list.

Parameters
collision

 

Private Attributes

DataManager dataManager
 Reference to the DataManager. Used for checking if the Skyhub is unlocked.
 
float cooldownTimer = 0
 Time when cooldown time is over (interactCooldown seconds in the future).
 
bool interactUsed
 True if the player has already interacted with an object and the cooldown needs to start.
 
float interactTimer
 Time when long press interaction will be complete (longPressLength seconds in the future).
 
bool longPressInteractionActive = false
 True during a long press interaction.
 

Member Function Documentation

◆ Awake()

void PlayerInteract.Awake ( )
private

Set reference to dataManager.

◆ OnTriggerEnter2D()

void PlayerInteract.OnTriggerEnter2D ( Collider2D collision)
private

Runs when an object enters the player's hitbox. Adds any newly touched interactables to the touchedInteractables list.

Parameters
collision

◆ OnTriggerExit2D()

void PlayerInteract.OnTriggerExit2D ( Collider2D collision)
private

Runs when an object exits the player's hitbox. Remove any untouched interactables from the touchedInteractables list.

Parameters
collision

◆ Update()

void PlayerInteract.Update ( )
private

Get all interactables currently overlapping with the player's hitbox (OnTriggerEnter() and OnTriggerExit())

  • Scan for objects on the interactable layers that are interactRange distance away from the attackPoint.
  • Combine the list of interactables near the attackPoint and the interactables currently touching the player. Tell all interactables within range that they are able to be interacted with. If the interact key is being pressed this frame...
  • If the interaction key is pressed, trigger the interaction for each object found in our scan and start the cooldown.
  • If the interaction key is held, then for each object found in our scan...
    • If the object has long press functionality...
      • Start and update the interaction timer
      • If the long press is timer is up, reset the timer and trigger the long press interaction.
    • Invoke the interactProgress event to update the interact progress bar.
  • If the player just interacted with something, start the cooldown timer and set

Otherwise...

  • The interact key is not being held down, so set keyDown to false.
  • Reset the interactTimer.
  • Invoke the interactProgress event to update the interact progress bar.

Member Data Documentation

◆ attackPoint

Transform PlayerInteract.attackPoint

Reference to the player's's attack point. It's a point in space that's a child of the player, existing some distance in front of it. Projectiles spawn from the attack point, and melee attacks scan for enemies to damage from a certain radius around it.

◆ cooldownTimer

float PlayerInteract.cooldownTimer = 0
private

Time when cooldown time is over (interactCooldown seconds in the future).

◆ dataManager

DataManager PlayerInteract.dataManager
private

Reference to the DataManager. Used for checking if the Skyhub is unlocked.

◆ interactableLayers

LayerMask PlayerInteract.interactableLayers

List of layers that the player can interact with objects on.

◆ interactCooldown

float PlayerInteract.interactCooldown = 0.5f

Cooldown time after an interaction has happened, in seconds.

◆ interactKey

string PlayerInteract.interactKey = "e"

Name of the key the player must press to interact with an object.

◆ interactRange

float PlayerInteract.interactRange = 0.5f

Distance from the attack point an object can be to allow interaction.

◆ interactTimer

float PlayerInteract.interactTimer
private

Time when long press interaction will be complete (longPressLength seconds in the future).

◆ interactUsed

bool PlayerInteract.interactUsed
private

True if the player has already interacted with an object and the cooldown needs to start.

◆ longPressInteractionActive

bool PlayerInteract.longPressInteractionActive = false
private

True during a long press interaction.

◆ longPressLength

float PlayerInteract.longPressLength = 1f

Amount of seconds the user should have to hold the interact button to trigger a long press interaction.

◆ previouslyInRange

Collider2D [] PlayerInteract.previouslyInRange

Keep track of which interactables were in range on the previous frame/game loop cycle. Used for triggerProximityEnter/Stay/Exit.

◆ touchedInteractables

List<Collider2D> PlayerInteract.touchedInteractables

List of all interactables overlapping with the player's hitbox.

Event Documentation

◆ interactProgress

Action<float> PlayerInteract.interactProgress
static

An event that reports the current progress on a long press interaction. Used for InteractProgressBar.


The documentation for this class was generated from the following file: