On-screen controls
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using Level;
|
||||
using DG.Tweening;
|
||||
|
||||
@@ -11,8 +12,11 @@ namespace Objects
|
||||
private static Player instance;
|
||||
|
||||
public Vector2Int layoutPosition;
|
||||
public InputActionAsset actions;
|
||||
|
||||
private bool isMoving = false;
|
||||
private InputAction moveAction;
|
||||
private InputAction testAction;
|
||||
|
||||
public static Player Instance => instance;
|
||||
public bool CanMove
|
||||
@@ -32,6 +36,9 @@ namespace Objects
|
||||
return;
|
||||
}
|
||||
instance = this;
|
||||
|
||||
moveAction = actions.FindActionMap("Gameplay").FindAction("Move");
|
||||
moveAction.Enable();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,22 +53,17 @@ namespace Objects
|
||||
{
|
||||
if (CanMove)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.DownArrow))
|
||||
Vector2 directionFloat = moveAction.ReadValue<Vector2>();
|
||||
directionFloat = Vector2.ClampMagnitude(directionFloat, 1f);
|
||||
Vector2Int direction = Vector2Int.RoundToInt(directionFloat);
|
||||
|
||||
// Allow movement along single axis only
|
||||
if (direction.x != 0 && direction.y != 0)
|
||||
{
|
||||
Move(Vector2Int.down);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.UpArrow))
|
||||
{
|
||||
Move(Vector2Int.up);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
Move(Vector2Int.left);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.RightArrow))
|
||||
{
|
||||
Move(Vector2Int.right);
|
||||
direction = new Vector2Int(direction.x, 0);
|
||||
}
|
||||
|
||||
Move(direction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user