only allow using elevator while on it

This commit is contained in:
2023-05-15 09:13:12 +02:00
parent 8de8301205
commit 0d451302e0
5 changed files with 67 additions and 27 deletions

View File

@@ -8,7 +8,7 @@ using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
namespace Station46.Modules.Elevated_Platform.Scripts
{
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(Animator), typeof(Collider))]
public class PlatformElevator : MonoBehaviour
{
public enum Status
@@ -34,7 +34,11 @@ namespace Station46.Modules.Elevated_Platform.Scripts
case Status.Bottom:
case Status.Top:
ReleasePlayer();
_button.Enable();
if (!_leftElevatorWhileMoving)
{
_button.Enable();
}
_leftElevatorWhileMoving = false;
break;
case Status.Moving:
_button.Disable();
@@ -49,6 +53,7 @@ namespace Station46.Modules.Elevated_Platform.Scripts
private Status _status = Status.Bottom;
private Animator _animator;
private Transform _previousPlayerParent;
private bool _leftElevatorWhileMoving;
private void Awake()
{
@@ -104,5 +109,28 @@ namespace Station46.Modules.Elevated_Platform.Scripts
throw new ArgumentOutOfRangeException();
}
}
private void OnTriggerEnter(Collider other)
{
if (_status != Status.Moving && other.CompareTag("MainCamera"))
{
_button.Enable();
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("MainCamera"))
{
if (_status == Status.Moving)
{
_leftElevatorWhileMoving = true;
}
else
{
_button.Disable();
}
}
}
}
}