Initial commit
This commit is contained in:
90
Assets/Scripts/Door.cs
Normal file
90
Assets/Scripts/Door.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class Door : MonoBehaviour, IInteractable
|
||||
{
|
||||
[SerializeField] bool autoDoor;
|
||||
[SerializeField] bool locked;
|
||||
[SerializeField] bool isOpen;
|
||||
[SerializeField] GameObject door;
|
||||
[SerializeField] float openHeight = 3f;
|
||||
[SerializeField] float openTime = 2f;
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
void OpenDoor(float height)
|
||||
{
|
||||
door.transform.Translate(0f,-height,0f);
|
||||
}
|
||||
|
||||
void CloseDoor(float height)
|
||||
{
|
||||
door.transform.Translate(0f,height,0f);
|
||||
}
|
||||
|
||||
public void Interact(GameObject interactor)
|
||||
{
|
||||
if (autoDoor)
|
||||
{
|
||||
if (!locked)
|
||||
door.transform.Translate(0f,-3f,0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("You need to use a key to open this door.");
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanInteract(GameObject interactor)
|
||||
{
|
||||
return !locked;
|
||||
}
|
||||
|
||||
public string GetInteractionPrompt()
|
||||
{
|
||||
return locked ? "Door is locked" : "Open door";
|
||||
}
|
||||
|
||||
public void OnHighlight()
|
||||
{
|
||||
// e.g. outline effect
|
||||
}
|
||||
|
||||
public void OnUnhighlight()
|
||||
{
|
||||
// remove outline
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user