Some Nice UI
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,12 +11,17 @@ public class PlayerStressController : MonoBehaviour
|
||||
[Header("Stress Settings")]
|
||||
public float currentStress = 0f;
|
||||
public float maxStress = 100f;
|
||||
|
||||
public bool isPanicking = false;
|
||||
public bool isParalyzed = false;
|
||||
|
||||
// Define the event
|
||||
public static event Action OnPlayerPanic;
|
||||
public static event Action OnPlayerCalm;
|
||||
|
||||
[Header("Panic Settings")]
|
||||
[SerializeField] private float panicDuration = 1.2f;
|
||||
private float panicEndTime;
|
||||
[SerializeField] private float paralyseDuration = 5f;
|
||||
|
||||
public bool IsPanicking => Time.time < panicEndTime;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -27,35 +33,59 @@ public class PlayerStressController : MonoBehaviour
|
||||
{
|
||||
while (true) // Runs for the lifetime of the object
|
||||
{
|
||||
ApplyStressLogic();
|
||||
yield return ApplyStressLogic();
|
||||
|
||||
// Wait for exactly 1 second before running again
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyStressLogic()
|
||||
IEnumerator ApplyStressLogic()
|
||||
{
|
||||
if (isParalyzed) yield break;
|
||||
|
||||
// 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)
|
||||
if (pickupController.heldObject != null && pickupController.heldObject.TryGetComponent<TrickController>(out _))
|
||||
{
|
||||
HandlePanic();
|
||||
currentStress += 5; // Increase stress based on number of carried tricks
|
||||
}
|
||||
|
||||
currentStress = Mathf.Clamp(currentStress, 0, maxStress);
|
||||
|
||||
if (!isPanicking && currentStress >= maxStress)
|
||||
{
|
||||
Debug.Log($"{currentStress}, {isPanicking}, {isParalyzed}");
|
||||
yield return HandlePanic();
|
||||
}
|
||||
|
||||
else if(isPanicking && currentStress < maxStress)
|
||||
{
|
||||
isPanicking = false;
|
||||
HandleCalm();
|
||||
Debug.Log("Player has calmed down.");
|
||||
}
|
||||
}
|
||||
|
||||
void HandlePanic()
|
||||
IEnumerator HandlePanic()
|
||||
{
|
||||
panicEndTime = Time.time + panicDuration;
|
||||
|
||||
isPanicking = true;
|
||||
Debug.Log("Player is freaking out man!");
|
||||
// Add effects like screen shake or slowing down the player here
|
||||
OnPlayerPanic?.Invoke(); // Trigger the panic event
|
||||
yield return StartCoroutine(HandleParalyze());
|
||||
}
|
||||
|
||||
void HandleCalm()
|
||||
{
|
||||
Debug.Log("Player is feeling better now!");
|
||||
OnPlayerCalm?.Invoke(); // Trigger the calm event
|
||||
}
|
||||
|
||||
public void ReduceStress(float amount)
|
||||
@@ -64,4 +94,15 @@ public class PlayerStressController : MonoBehaviour
|
||||
currentStress = Mathf.Clamp(currentStress, 0, maxStress);
|
||||
Debug.Log($"Stress reduced by {amount}. Current Stress: {currentStress}");
|
||||
}
|
||||
|
||||
IEnumerator HandleParalyze()
|
||||
{
|
||||
isParalyzed = true;
|
||||
Debug.Log("Player is paralyzed.");
|
||||
|
||||
yield return new WaitForSecondsRealtime(paralyseDuration);
|
||||
|
||||
Debug.Log("Player has recovered from paralysis.");
|
||||
isParalyzed = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user