added inventory and stamina system
This commit is contained in:
36
Assets/Scripts/StaminaBoostPickup.cs
Normal file
36
Assets/Scripts/StaminaBoostPickup.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user