Cache full pickup object on Pulver

This commit is contained in:
Michal Pikulski
2025-09-08 15:09:45 +02:00
parent f4a183d524
commit 2e24b343c3

View File

@@ -65,6 +65,11 @@ public class FollowerController : MonoBehaviour
private bool lastInteractionSuccess = true; private bool lastInteractionSuccess = true;
/// <summary>
/// Cache for the currently picked-up GameObject (hidden while held).
/// </summary>
private GameObject cachedPickupObject = null;
/// <summary> /// <summary>
/// Set to true if the follower just combined items. /// Set to true if the follower just combined items.
/// </summary> /// </summary>
@@ -329,31 +334,29 @@ public class FollowerController : MonoBehaviour
if (justCombined) if (justCombined)
{ {
// Combination: just destroy the pickup, don't spawn anything // Combination: just destroy the pickup, don't spawn anything
if (cachedPickupObject != null)
{
Destroy(cachedPickupObject);
cachedPickupObject = null;
}
GameObject.Destroy(pickup.gameObject); GameObject.Destroy(pickup.gameObject);
justCombined = false; justCombined = false;
break; break;
} }
// Swap logic: if holding an item, drop it here // Swap logic: if holding an item, drop it here
if (currentlyHeldItem != null) if (currentlyHeldItem != null && cachedPickupObject != null)
{ {
var basePickupPrefab = GameManager.Instance.BasePickupPrefab; // Drop the cached object at the pickup's position
if (basePickupPrefab != null) cachedPickupObject.transform.position = pickup.transform.position;
{ cachedPickupObject.transform.SetParent(null);
var droppedPickupObj = GameObject.Instantiate(basePickupPrefab, pickup.transform.position, Quaternion.identity); cachedPickupObject.SetActive(true);
var droppedPickup = droppedPickupObj.GetComponent<Pickup>(); cachedPickupObject = null;
if (droppedPickup != null)
{
droppedPickup.itemData = currentlyHeldItem;
droppedPickup.ApplyItemData();
}
}
else
{
Debug.LogWarning("BasePickup prefab not assigned in GameSettings");
}
} }
SetHeldItem(pickup.itemData); SetHeldItem(pickup.itemData);
GameObject.Destroy(pickup.gameObject); // Cache and hide the picked up object
cachedPickupObject = pickup.gameObject;
cachedPickupObject.SetActive(false);
cachedPickupObject.transform.SetParent(this.transform);
break; break;
} }
} }