sfdagsghds

This commit is contained in:
Janis Meister
2023-02-23 13:44:57 +01:00
parent 1a9bcccfba
commit f85588e144
5 changed files with 69 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ public class PlayerController : MonoBehaviour
public static Action OnActiveSlotChanged;
public Item testItem1;
public Item testItem2;
public float interactionDistance = 2.5f;
public int hotbarSlotCount = 9;
public int activeHotbarSlot = 0;
[SerializeField] private Inventory playerInventory;
@@ -44,6 +44,26 @@ public class PlayerController : MonoBehaviour
GuiManager.Instance.TogglePanel("Inventory");
}
if (Input.GetMouseButtonDown(0))
{
Vector3Int snappedMousePosition = GridBuildingSystem.Instance.GetSnappedMousePosition();
Vector3Int snappedPlayerPosition = GridBuildingSystem.Instance.GetSnappedPosition(gameObject.transform.position);
if (Vector3Int.Distance(snappedMousePosition, snappedPlayerPosition) <= interactionDistance)
{
if (playerInventory.items[activeHotbarSlot]?.item is Tool)
{
Tool tool = playerInventory.items[activeHotbarSlot].item as Tool;
tool.Use();
}
}
else
{
Debug.Log("Not in range");
}
}
//! DEBUG
if (Input.GetKeyDown(KeyCode.U))
{