using UnityEngine;
///
/// Add to a pickup GameObject alongside PickupItem.
/// When the item is collected, applies a one-time boost to the player's max stamina.
///
[RequireComponent(typeof(PickupItem))]
public class StaminaBoostPickup : MonoBehaviour
{
[Tooltip("Max stamina will be set to this value when picked up.")]
public float newMaxStamina = 200f;
void Start()
{
// Hook into PickupItem's collect event via a simple poll
var pickup = GetComponent();
// We override by watching PickupItem's collected state each frame
StartCoroutine(WatchForCollect(pickup));
}
System.Collections.IEnumerator WatchForCollect(PickupItem pickup)
{
// Wait until the pickup is destroyed (collected)
while (pickup != null)
yield return null;
// Find player and apply boost
Player p = FindObjectOfType();
if (p != null)
{
p.maxStamina = newMaxStamina;
p.stamina = newMaxStamina;
Debug.Log($"[StaminaBoost] Max stamina set to {newMaxStamina}");
}
}
}