Done?
This commit is contained in:
@@ -9,8 +9,14 @@ namespace Objects
|
||||
{
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
// Static
|
||||
private static Player instance;
|
||||
|
||||
// Events
|
||||
public delegate void PlayerMovedHandler();
|
||||
public event PlayerMovedHandler PlayerMoved;
|
||||
|
||||
// Public
|
||||
public Vector2Int layoutPosition;
|
||||
public InputActionAsset actions;
|
||||
|
||||
@@ -51,7 +57,7 @@ namespace Objects
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (CanMove)
|
||||
if (CanMove && moveAction.WasPressedThisFrame())
|
||||
{
|
||||
Vector2 directionFloat = moveAction.ReadValue<Vector2>();
|
||||
directionFloat = Vector2.ClampMagnitude(directionFloat, 1f);
|
||||
@@ -94,7 +100,12 @@ namespace Objects
|
||||
LayoutCell currentCell = LevelBuilder.Instance.GetCellAtLayout(layoutPosition);
|
||||
LayoutCell targetCell = LevelBuilder.Instance.GetCellAtLayout(layoutPosition + direction);
|
||||
|
||||
if (targetCell != null && targetCell.IsFree)
|
||||
if (targetCell == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetCell.IsFree)
|
||||
{
|
||||
// Free previous cell
|
||||
currentCell.cellData.cellContent = LayoutCell.LayoutCellData.CellContent.None;
|
||||
@@ -109,10 +120,12 @@ namespace Objects
|
||||
isMoving = true;
|
||||
transform.DOMove(targetCell.worldPos, 1f).OnComplete(() => isMoving = false);
|
||||
}
|
||||
else if (targetCell != null && targetCell.cellData.cellContent == LayoutCell.LayoutCellData.CellContent.Crate)
|
||||
else if (targetCell.cellData.cellContent == LayoutCell.LayoutCellData.CellContent.Crate)
|
||||
{
|
||||
targetCell.crate.Move(direction);
|
||||
}
|
||||
|
||||
PlayerMoved?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user