36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
|
using Pausable;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace Interactable.Interactor
|
||
|
{
|
||
|
public class KeyPressInteractor : ColliderTriggerInteractor, IPausable
|
||
|
{
|
||
|
protected bool isPlayerInside = false;
|
||
|
protected Input.PlayerInput playerInput = null;
|
||
|
|
||
|
protected override void Start()
|
||
|
{
|
||
|
base.Start();
|
||
|
|
||
|
playerInput = new Input.PlayerInput();
|
||
|
playerInput.Enable();
|
||
|
playerInput.PlayerControl.Interact.performed += (context) => Interact();
|
||
|
}
|
||
|
|
||
|
protected virtual void Interact()
|
||
|
{
|
||
|
if (IsPaused && isPlayerInside)
|
||
|
interactable.Interact();
|
||
|
}
|
||
|
|
||
|
protected override void OnTriggerEnter2D(Collider2D other)
|
||
|
=> isPlayerInside = true;
|
||
|
protected virtual void OnTriggerExit2D(Collider2D other)
|
||
|
=> isPlayerInside = false;
|
||
|
|
||
|
public bool IsPaused { get; protected set; } = false;
|
||
|
public void Pause() => IsPaused = true;
|
||
|
public void Resume() => IsPaused = false;
|
||
|
}
|
||
|
}
|