[Player][Interactions] Items can be switched when picked up now
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user