58 lines
1.3 KiB
C#
58 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
public class RoomDoor : Interactable
|
|
{
|
|
public RoomDoor linkedDoor;
|
|
public bool requiresInteraction; // Do we need to press a button to enter?
|
|
|
|
// transform that the character should walk towards when entering the room
|
|
// through this door
|
|
public Transform WalkDirection;
|
|
TeleportHandler teleportHandler;
|
|
|
|
// not required and only plays if interaction is required
|
|
public Animation doorAnimator;
|
|
public AnimationClip openDoor;
|
|
public AnimationClip closeDoor;
|
|
|
|
private void Start()
|
|
{
|
|
teleportHandler = GameObject.FindWithTag("Player").GetComponent<TeleportHandler>();
|
|
}
|
|
|
|
public override void Interact()
|
|
{
|
|
if (requiresInteraction)
|
|
{
|
|
if (doorAnimator && openDoor)
|
|
{
|
|
doorAnimator.clip = openDoor;
|
|
doorAnimator.Play();
|
|
}
|
|
teleportHandler.EnterRoom(this);
|
|
}
|
|
}
|
|
|
|
public void CloseDoor()
|
|
{
|
|
if (doorAnimator && closeDoor)
|
|
{
|
|
doorAnimator.clip = closeDoor;
|
|
doorAnimator.Play();
|
|
}
|
|
}
|
|
|
|
public override void MoveInsideRange()
|
|
{
|
|
if (!requiresInteraction)
|
|
{
|
|
teleportHandler.EnterRoom(this);
|
|
}
|
|
}
|
|
|
|
public override void MoveOutsideRange()
|
|
{
|
|
// Do nothing
|
|
}
|
|
}
|