Interactable Triggers Added
This commit is contained in:
8
Assets/Scripts/Interactable/Interactor.meta
Normal file
8
Assets/Scripts/Interactable/Interactor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 977bd97ca45d4a1479f8f78e46297bef
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Interactable.Interactor
|
||||
{
|
||||
[RequireComponent(typeof(Collider2D), typeof(Rigidbody2D))]
|
||||
public class ColliderTriggerInteractor : MonoBehaviour
|
||||
{
|
||||
protected IInteractable interactable = null;
|
||||
protected virtual void Start()
|
||||
{
|
||||
interactable = GetComponent<IInteractable>();
|
||||
GetComponent<Collider2D>().isTrigger = true;
|
||||
GetComponent<Rigidbody2D>().isKinematic = true;
|
||||
}
|
||||
protected virtual void OnTriggerEnter2D(Collider2D other) => interactable.Interact();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c53f90e7ee31f3d45b696e5a54b098b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
Assets/Scripts/Interactable/Interactor/KeyPressInteractor.cs
Normal file
35
Assets/Scripts/Interactable/Interactor/KeyPressInteractor.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43ee1645cb5332c4b86608159117c837
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user