37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Add to a pickup GameObject alongside PickupItem.
|
|
/// When the item is collected, applies a one-time boost to the player's max stamina.
|
|
/// </summary>
|
|
[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<PickupItem>();
|
|
// 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<Player>();
|
|
if (p != null)
|
|
{
|
|
p.maxStamina = newMaxStamina;
|
|
p.stamina = newMaxStamina;
|
|
Debug.Log($"[StaminaBoost] Max stamina set to {newMaxStamina}");
|
|
}
|
|
}
|
|
}
|