[Player][Interactions] Items can be switched when picked up now

This commit is contained in:
Michal Pikulski
2025-09-04 11:50:02 +02:00
parent 387f11ab4a
commit 496ef10b8b
10 changed files with 93 additions and 2 deletions

View File

@@ -258,7 +258,7 @@ public class FollowerController : MonoBehaviour
yield return null;
}
OnPickupArrived?.Invoke();
// Set held item and destroy pickup
// Swap held item if necessary, then set held item and destroy pickup
if (heldObjectRenderer != null)
{
Collider2D[] hits = Physics2D.OverlapCircleAll(itemPosition, 0.2f);
@@ -267,6 +267,25 @@ public class FollowerController : MonoBehaviour
var pickup = hit.GetComponent<Pickup>();
if (pickup != null)
{
// Swap logic: if holding an item, drop it here
if (currentlyHeldItem != null)
{
var basePickupPrefab = GameManager.Instance.BasePickupPrefab;
if (basePickupPrefab != null)
{
var droppedPickupObj = GameObject.Instantiate(basePickupPrefab, pickup.transform.position, Quaternion.identity);
var droppedPickup = droppedPickupObj.GetComponent<Pickup>();
if (droppedPickup != null)
{
droppedPickup.itemData = currentlyHeldItem;
droppedPickup.ApplyItemData();
}
}
else
{
Debug.LogWarning("BasePickup prefab not assigned in GameSettings");
}
}
SetHeldItem(pickup.itemData);
GameObject.Destroy(pickup.gameObject);
break;