From c8b8bec7b3ea533e3b7b0b2db03cc51101deccd6 Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Tue, 01 Apr 2025 17:04:30 +0000 Subject: [PATCH] #21 added floating ore text --- Assets/Scripts/Managers/GameManager.cs | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index e0670dd..41e5ace 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -14,8 +14,10 @@ public GameObject damageTextPrefab; public GameObject healthTextPrefab; + public GameObject lootTextPrefab; public Canvas playerUI; public Canvas pauseMenuUI; + public Canvas worldSpaceUI; public GameObject levelChanger; public Tilemap tilemap; [NonSerialized] @@ -112,6 +114,20 @@ tmpText.text = healthRestored.ToString(); } + public void CharacterLootObtained(Vector3 position, Item itemReceived, int quantity) + { + // Offset the position slightly up so it doesn't spawn inside the ground/player + position += Vector3.up * 0.5f; + + // Create text in world space (no parent needed) + GameObject textObj = Instantiate(lootTextPrefab, position, Quaternion.identity, worldSpaceUI.transform); + TextMeshProUGUI tmpText = textObj.GetComponent<TextMeshProUGUI>(); + tmpText.text = $"+{quantity} ({itemReceived.itemName})"; + + // Ensure it's visible to the camera + textObj.transform.rotation = Camera.main.transform.rotation; + + } public void CharacterDrill(ContactPoint2D contact, DrillDirection drillDirection) { GridLayout grid = tilemap.transform.GetComponentInParent<GridLayout>(); @@ -140,14 +156,19 @@ // middle of tile cellWorldPosition.x += 0.5f; cellWorldPosition.y += 0.5f; - if (tileGameObject?.GetComponent<Dropable>()?.isDropable ?? false) + Dropable dropable = tileGameObject?.GetComponent<Dropable>(); + if (dropable?.isDropable ?? false) { // Change no drops, only inventory //Instantiate(tileGameObject?.GetComponent<Dropable>().dropable, cellWorldPosition, Quaternion.identity, pickups.transform); Inventory playerInventory = contact.rigidbody.gameObject.GetComponent<Inventory>(); if (playerInventory != null) { - playerInventory.AddItem(tileGameObject?.GetComponent<Dropable>().dropable); + Item item = dropable.dropable; + playerInventory.AddItem(item, dropable.dropAmount); + Debug.Log("CellWorldPosition: " + cellWorldPosition); + Debug.Log("TileGameObjectPosition: " + tileGameObject.transform.position); + CharacterLootObtained(tileGameObject.transform.position, item, dropable.dropAmount); } } tilemap.SetTile(cellCoord, null); -- Gitblit v1.9.3