BGJ-2022.1/Assets/Scripts/Interactable/Interactor/KeyPressInteractor.cs

36 lines
1.0 KiB
C#
Raw Permalink Normal View History

2022-02-22 21:57:18 +03:00
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;
}
}