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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
22
Assets/Scripts/UI/GamplayOnscreenControls.cs
Normal file
22
Assets/Scripts/UI/GamplayOnscreenControls.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GamplayOnscreenControls : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject uiContainer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
uiContainer.SetActive(false);
|
||||
GameManager.Instance.GameStateChanged += OnGameStateChanged;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
GameManager.Instance.GameStateChanged -= OnGameStateChanged;
|
||||
}
|
||||
|
||||
private void OnGameStateChanged(GameState newState)
|
||||
{
|
||||
uiContainer.SetActive(newState == GameState.Gameplay);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15f5812966af1954d91c4347cac9e80e
|
||||
guid: 12f193df5b2ac6c4db99918efaf29746
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,16 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Vector2IntSerializable
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public Vector2IntSerializable(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user