[Input][Interaction] Add interactable items

This commit is contained in:
Michal Pikulski
2025-09-01 16:14:21 +02:00
parent 8b0f6b9376
commit 8e1174d4bf
11 changed files with 725 additions and 79 deletions

55
Assets/Scripts/Pickup.cs Normal file
View File

@@ -0,0 +1,55 @@
using UnityEngine;
public class Pickup : MonoBehaviour
{
public PickupItemData itemData;
public SpriteRenderer iconRenderer;
private Interactable interactable;
void Awake()
{
if (iconRenderer == null)
iconRenderer = GetComponent<SpriteRenderer>();
interactable = GetComponent<Interactable>();
if (interactable != null)
{
interactable.Interacted += OnInteracted;
}
ApplyItemData();
}
void OnDestroy()
{
if (interactable != null)
{
interactable.Interacted -= OnInteracted;
}
}
#if UNITY_EDITOR
void OnValidate()
{
if (iconRenderer == null)
iconRenderer = GetComponent<SpriteRenderer>();
ApplyItemData();
}
#endif
public void ApplyItemData()
{
if (itemData != null)
{
if (iconRenderer != null)
iconRenderer.sprite = itemData.mapSprite;
gameObject.name = itemData.itemName;
// Optionally update other fields, e.g. description
}
}
private void OnInteracted()
{
Debug.Log($"Pickup.OnInteracted: Picked up {itemData?.itemName}");
// TODO: Add item to inventory manager here
Destroy(gameObject);
}
}