1
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using BITKit.Sensors;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
@@ -6,24 +7,16 @@ namespace BITKit.Entities.Player
|
||||
public class EntityInteractive : EntityPlayerComponent
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public float distance;
|
||||
public LayerMask layerMask;
|
||||
|
||||
[Header(Constant.Header.Input)]
|
||||
public InputActionReference interactiveAction;
|
||||
private readonly InputActionGroup inputActionGroup = new();
|
||||
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
[SerializeField] private Transform cameraTransform;
|
||||
[SerializeReference, SubclassSelector] private ISensor sensor;
|
||||
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
private ISelectable selected;
|
||||
private IntervalUpdate cd = new(0.08f);
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (Physics.Raycast(cameraTransform.position,cameraTransform.forward, out var raycastHit, distance, layerMask,QueryTriggerInteraction.Collide))
|
||||
if (sensor.Get().TryGetAny(x=>x.TryGetComponentAny<ISelectable>(out _),out var detected))
|
||||
{
|
||||
if (raycastHit.transform.TryGetComponentAny<ISelectable>(out var _detected))
|
||||
if (detected.TryGetComponentAny<ISelectable>(out var _detected))
|
||||
{
|
||||
if (_detected == selected)
|
||||
{
|
||||
@@ -68,7 +61,7 @@ namespace BITKit.Entities.Player
|
||||
}
|
||||
public void Interactive(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.interaction is not PressInteraction || !context.performed) return;
|
||||
if (context.interaction is not PressInteraction || !context.performed || cd.AllowUpdate is false) return;
|
||||
var _selected = selected;
|
||||
if (_selected is not MonoBehaviour monoBehaviour) return;
|
||||
if (monoBehaviour.TryGetComponentAny<IAction>(out var action))
|
||||
|
Reference in New Issue
Block a user