Key-Door System
Physical progression gating using carried key objects and interaction prompts
Overview
The key door system gates progression by requiring the player to carry a physical key to a locked door. When in range, an interaction prompt appears and the door unlocks with animation and audio.
GIF Preview
Main Responsibilities
- Checks if player is holding a valid key.
- Validates distance before unlocking.
- Handles animation, collision, and audio.
- Displays consistent interaction prompt.
Unlock Check
bool InRange()
{
return Vector3.Distance(player.transform.position, door.transform.position) < unlockRange;
}
void TryUnlock()
{
if (player.IsHoldingKey && InRange())
{
doorAnimator.SetTrigger("Unlock");
doorCollider.enabled = false;
FN_SoundManager.PlaySound(SoundType.DoorUnlock, 1f);
}
}
validates key and distance before unlock
Prompt Logic
void Update()
{
if (player.IsHoldingKey && InRange())
{
interactPrompt.Show("Press E to unlock");
if (Input.GetKeyDown(KeyCode.E))
TryUnlock();
}
else
{
interactPrompt.Hide();
}
}
shows prompt and waits for input