Files
ggj2026/Assets/Scripts/PlayerStressController.cs
T
2026-01-31 20:03:45 -06:00

60 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class PlayerStressController : MonoBehaviour
{
public PlayerPickupController pickupController;
[Header("Stress Settings")]
public float currentStress = 0f;
public float maxStress = 100f;
void Start()
{
// Start the repeating loop
StartCoroutine(StressCheckLoop());
}
IEnumerator StressCheckLoop()
{
while (true) // Runs for the lifetime of the object
{
ApplyStressLogic();
// Wait for exactly 1 second before running again
yield return new WaitForSeconds(1.0f);
}
}
void ApplyStressLogic()
{
// Find all objects tagged as "Enemy"
List<GameObject> enemies = GameObject.FindGameObjectsWithTag("Interactable").Where(enemy => enemy.GetComponent<TrickController>() != null).ToList();
// Keep stress within 0 and Max
currentStress = Mathf.Clamp(currentStress, 0, maxStress);
currentStress += enemies.Count; // Increase stress based on number of enemies nearby
Debug.Log($"Current Stress: {currentStress}");
if (currentStress >= maxStress)
{
HandlePanic();
}
}
void HandlePanic()
{
Debug.Log("Player is freaking out man!");
// Add effects like screen shake or slowing down the player here
}
public void ReduceStress(float amount)
{
currentStress -= amount;
currentStress = Mathf.Clamp(currentStress, 0, maxStress);
Debug.Log($"Stress reduced by {amount}. Current Stress: {currentStress}");
}
}