chunk 1: core gameplay scripts scenes runtime assets
This commit is contained in:
1316
Assets/Scripts/Health-Stamina Scripts/HealthNew.cs
Normal file
1316
Assets/Scripts/Health-Stamina Scripts/HealthNew.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Assets/Scripts/Health-Stamina Scripts/HealthNew.cs.meta
Normal file
11
Assets/Scripts/Health-Stamina Scripts/HealthNew.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35a1e0f9ef29cc44c926ef8161a0c017
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
125
Assets/Scripts/Health-Stamina Scripts/StaminaSystem.cs
Normal file
125
Assets/Scripts/Health-Stamina Scripts/StaminaSystem.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI; // Add this line to use Unity's UI components
|
||||
|
||||
public class StaminaSystem : MonoBehaviour
|
||||
{
|
||||
public float maxStamina;
|
||||
public float currentStamina;
|
||||
public float staminaRegenerationRate;
|
||||
|
||||
//public Text staminaText; // Reference to the UI Text component for displaying stamina
|
||||
//public Slider staminaSlider; // Reference to the UI Slider component for visualizing stamina
|
||||
public Image staminaCircle;
|
||||
|
||||
private bool isExhausted = false;
|
||||
|
||||
[SerializeField]
|
||||
ParticleSystem lowStaminaVFX;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
maxStamina = 100f;
|
||||
staminaRegenerationRate = 0.1f;
|
||||
currentStamina = maxStamina;
|
||||
|
||||
// Check if lowStaminaVFX is assigned
|
||||
if (lowStaminaVFX == null)
|
||||
{
|
||||
DevLog.LogWarning("Low stamina VFX not assigned on " + gameObject.name);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// CompareTag avoids string allocation per frame (was gameObject.tag == "...")
|
||||
if (gameObject.CompareTag("Player") && currentStamina < 99)
|
||||
ReplenishStamina(0.1f);
|
||||
if (gameObject.CompareTag("Enemy") && currentStamina < 99)
|
||||
ReplenishStamina(0.015f);
|
||||
|
||||
// Check if lowStaminaVFX is assigned before using it
|
||||
if (lowStaminaVFX != null)
|
||||
{
|
||||
if (currentStamina / maxStamina > 0.1 && lowStaminaVFX.isPlaying)
|
||||
{
|
||||
lowStaminaVFX.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isExhausted)
|
||||
{
|
||||
UpdateStaminaUI(); // Update UI to reflect changes in stamina
|
||||
}
|
||||
}
|
||||
|
||||
public void UseStamina(float amount)
|
||||
{
|
||||
//print("stamina used in: " + gameObject.tag);
|
||||
if (!isExhausted)
|
||||
{
|
||||
|
||||
currentStamina -= amount;
|
||||
|
||||
//currentStamina = Mathf.Clamp(currentStamina, 0f, maxStamina);
|
||||
|
||||
if (currentStamina <= 0f)
|
||||
{
|
||||
currentStamina = 0;
|
||||
isExhausted = true;
|
||||
// Perform any actions when stamina is fully depleted (e.g., disable running)
|
||||
//disable attacks
|
||||
//disable running
|
||||
}
|
||||
|
||||
// Check if lowStaminaVFX is assigned before using it
|
||||
if (lowStaminaVFX != null)
|
||||
{
|
||||
if (currentStamina/maxStamina < 0.1)
|
||||
{
|
||||
lowStaminaVFX.Play();
|
||||
}
|
||||
else if(currentStamina/maxStamina > 0.1 && lowStaminaVFX.isPlaying)
|
||||
{
|
||||
lowStaminaVFX.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
UpdateStaminaUI(); // Update UI to reflect changes in stamina
|
||||
}
|
||||
}
|
||||
|
||||
public void ReplenishStamina(float amount)
|
||||
{
|
||||
currentStamina += amount;
|
||||
|
||||
// Add a clamp to prevent stamina from exceeding maxStamina
|
||||
currentStamina = Mathf.Clamp(currentStamina, 0f, maxStamina);
|
||||
|
||||
if (currentStamina > 0f)
|
||||
{
|
||||
isExhausted = false;
|
||||
}
|
||||
|
||||
UpdateStaminaUI(); // Update UI to reflect changes in stamina
|
||||
}
|
||||
|
||||
private void UpdateStaminaUI()
|
||||
{
|
||||
// Update the UI components to display the current stamina
|
||||
// Add null check for staminaCircle
|
||||
if (staminaCircle != null)
|
||||
{
|
||||
staminaCircle.fillAmount = currentStamina / maxStamina;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only log this once to avoid spamming the console
|
||||
if (Time.frameCount % 300 == 0) // Log approximately every 5 seconds at 60 FPS
|
||||
{
|
||||
DevLog.LogWarning("Stamina circle reference is null on " + gameObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Health-Stamina Scripts/StaminaSystem.cs.meta
Normal file
11
Assets/Scripts/Health-Stamina Scripts/StaminaSystem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1ee24a0d538b9a4f86b400c6f262285
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user