Cache full pickup object on Pulver
This commit is contained in:
@@ -65,6 +65,11 @@ public class FollowerController : MonoBehaviour
|
||||
|
||||
private bool lastInteractionSuccess = true;
|
||||
|
||||
/// <summary>
|
||||
/// Cache for the currently picked-up GameObject (hidden while held).
|
||||
/// </summary>
|
||||
private GameObject cachedPickupObject = null;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if the follower just combined items.
|
||||
/// </summary>
|
||||
@@ -329,31 +334,29 @@ public class FollowerController : MonoBehaviour
|
||||
if (justCombined)
|
||||
{
|
||||
// Combination: just destroy the pickup, don't spawn anything
|
||||
if (cachedPickupObject != null)
|
||||
{
|
||||
Destroy(cachedPickupObject);
|
||||
cachedPickupObject = null;
|
||||
}
|
||||
GameObject.Destroy(pickup.gameObject);
|
||||
justCombined = false;
|
||||
break;
|
||||
}
|
||||
// Swap logic: if holding an item, drop it here
|
||||
if (currentlyHeldItem != null)
|
||||
if (currentlyHeldItem != null && cachedPickupObject != 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");
|
||||
}
|
||||
// Drop the cached object at the pickup's position
|
||||
cachedPickupObject.transform.position = pickup.transform.position;
|
||||
cachedPickupObject.transform.SetParent(null);
|
||||
cachedPickupObject.SetActive(true);
|
||||
cachedPickupObject = null;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user