2026-01-13 15:43:33 +00:00
|
|
|
using Unity.VisualScripting;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Rendering;
|
|
|
|
|
|
|
|
|
|
public class Door : MonoBehaviour, IInteractable
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] GameObject door;
|
|
|
|
|
[SerializeField] float openHeight = 3f;
|
|
|
|
|
[SerializeField] float openTime = 2f;
|
2026-01-16 16:53:33 +00:00
|
|
|
[SerializeField] AudioClip audioClip;
|
|
|
|
|
[SerializeField] bool autoDoor;
|
|
|
|
|
[SerializeField] bool locked;
|
|
|
|
|
[SerializeField] bool isOpen;
|
|
|
|
|
[SerializeField] bool singleUse;
|
2026-01-13 15:43:33 +00:00
|
|
|
void OnTriggerEnter(Collider other)
|
|
|
|
|
{
|
|
|
|
|
if(other.CompareTag("Player") && autoDoor && !locked && !isOpen)
|
|
|
|
|
{
|
|
|
|
|
OpenDoor(openHeight);
|
|
|
|
|
isOpen = true;
|
|
|
|
|
}
|
|
|
|
|
else if(other.CompareTag("Player") && autoDoor && locked)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("The door is locked.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void OnTriggerExit(Collider other)
|
|
|
|
|
{
|
|
|
|
|
if(other.CompareTag("Player") && autoDoor && isOpen)
|
|
|
|
|
{
|
|
|
|
|
CloseDoor(openHeight);
|
|
|
|
|
isOpen = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-16 16:53:33 +00:00
|
|
|
public void OpenDoor(float height)
|
2026-01-13 15:43:33 +00:00
|
|
|
{
|
|
|
|
|
door.transform.Translate(0f,-height,0f);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 16:53:33 +00:00
|
|
|
public void CloseDoor(float height)
|
2026-01-13 15:43:33 +00:00
|
|
|
{
|
|
|
|
|
door.transform.Translate(0f,height,0f);
|
2026-01-16 16:53:33 +00:00
|
|
|
if(singleUse)
|
|
|
|
|
locked = true;
|
|
|
|
|
}
|
|
|
|
|
public void LockDoor()
|
|
|
|
|
{
|
|
|
|
|
locked = true;
|
|
|
|
|
}
|
|
|
|
|
public void UnlockDoor()
|
|
|
|
|
{
|
|
|
|
|
locked = false;
|
2026-01-13 15:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Interact(GameObject interactor)
|
|
|
|
|
{
|
2026-01-13 17:33:30 +00:00
|
|
|
if (!autoDoor)
|
2026-01-13 15:43:33 +00:00
|
|
|
{
|
2026-01-13 17:33:30 +00:00
|
|
|
if (!locked && !isOpen)
|
|
|
|
|
{
|
|
|
|
|
OpenDoor(openHeight);
|
|
|
|
|
isOpen = true;
|
|
|
|
|
}
|
|
|
|
|
else if (!locked && isOpen)
|
|
|
|
|
{
|
|
|
|
|
CloseDoor(openHeight);
|
|
|
|
|
isOpen = false;
|
|
|
|
|
}
|
|
|
|
|
else if (locked)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("The door is locked.");
|
|
|
|
|
}
|
2026-01-13 15:43:33 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-01-13 17:33:30 +00:00
|
|
|
return;
|
2026-01-13 15:43:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanInteract(GameObject interactor)
|
|
|
|
|
{
|
2026-01-13 17:33:30 +00:00
|
|
|
return !locked;
|
2026-01-13 15:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetInteractionPrompt()
|
|
|
|
|
{
|
2026-01-13 17:33:30 +00:00
|
|
|
if (locked)
|
2026-01-16 16:53:33 +00:00
|
|
|
return "Door is locked";
|
|
|
|
|
if(autoDoor)
|
|
|
|
|
return "";
|
2026-01-13 17:33:30 +00:00
|
|
|
return isOpen ? "Press [E] to close door" : "Press [E] to open door";
|
2026-01-16 16:53:33 +00:00
|
|
|
|
2026-01-13 15:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnHighlight()
|
|
|
|
|
{
|
|
|
|
|
// e.g. outline effect
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnUnhighlight()
|
|
|
|
|
{
|
|
|
|
|
// remove outline
|
|
|
|
|
}
|
|
|
|
|
}
|