Add interaction input handling
This commit is contained in:
parent
72a0daf486
commit
5772da3965
5 changed files with 116 additions and 2 deletions
|
@ -12,6 +12,35 @@ public class Player : MonoBehaviour
|
|||
private bool isWalking;
|
||||
private Vector3 lastInteractDir;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
gameInput.OnInteractAction += GameInput_OnInteractAction;
|
||||
}
|
||||
|
||||
private void GameInput_OnInteractAction(object sender, System.EventArgs e)
|
||||
{
|
||||
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
|
||||
|
||||
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
|
||||
|
||||
// Kepp a constantly updating record of the last move direction.
|
||||
// This means you can interact without holding down a direction.
|
||||
if (moveDir != Vector3.zero)
|
||||
{
|
||||
lastInteractDir = moveDir;
|
||||
}
|
||||
|
||||
float interactDistance = 2f;
|
||||
if (Physics.Raycast(transform.position, lastInteractDir, out RaycastHit raycastHit, interactDistance, countersLayerMask))
|
||||
{
|
||||
if (raycastHit.transform.TryGetComponent(out ClearCounter clearCounter))
|
||||
{
|
||||
// Has Clear Counter
|
||||
clearCounter.Interact();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
HandleMovement();
|
||||
|
@ -45,7 +74,7 @@ public class Player : MonoBehaviour
|
|||
if (raycastHit.transform.TryGetComponent(out ClearCounter clearCounter))
|
||||
{
|
||||
// Has Clear Counter
|
||||
clearCounter.Interact();
|
||||
//clearCounter.Interact();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue