Merged Main
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b88e05c37f07ccf48bcc436a9d7def5d
|
||||
Reference in New Issue
Block a user