Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/PlayerVitalsExample.cs
2026-02-21 16:45:37 +08:00

154 lines
2.9 KiB
C#

using UnityEngine;
using UnityEngine.UI;
public class PlayerVitalsExample : MonoBehaviour
{
private GameObject uniStormSystem;
private UniStormWeatherSystem_C uniStormSystemScript;
public int food = 100;
public float dryness = 100f;
public float warmth = 100f;
private bool isSheltered;
private bool foodCalculated;
public string shelterTag = "Shelter";
public Text foodText;
public Text drynessText;
public Text warmthText;
public Text shelteredText;
private void Awake()
{
uniStormSystem = GameObject.Find("UniStormSystemEditor");
uniStormSystemScript = uniStormSystem.GetComponent<UniStormWeatherSystem_C>();
}
private void Start()
{
if (uniStormSystem == null)
{
Debug.LogError("<color=red>Null Reference:</color> You must have the UniStorm Editor in your scene and named 'UniStormSystemEditor'. Make sure your C# UniStorm Editor has this name. ");
}
}
private void Update()
{
if (!(uniStormSystem != null))
{
return;
}
if (uniStormSystemScript.temperature <= 50 && !isSheltered)
{
warmth -= Time.deltaTime * 0.5f;
}
if (uniStormSystemScript.minuteCounter >= 59 && !foodCalculated)
{
food--;
foodCalculated = true;
}
if (uniStormSystemScript.minuteCounter <= 58)
{
foodCalculated = false;
}
if (uniStormSystemScript.temperature >= 51 && !isSheltered && uniStormSystemScript.minRainIntensity <= 0f)
{
warmth += Time.deltaTime * 0.5f;
if (warmth >= 100f)
{
warmth = 100f;
}
}
if ((uniStormSystemScript.minRainIntensity >= 50f && !isSheltered) || (uniStormSystemScript.minSnowIntensity >= 50f && !isSheltered))
{
dryness -= Time.deltaTime * 0.5f;
warmth -= Time.deltaTime * 0.5f;
}
else
{
dryness += Time.deltaTime * 0.5f;
if (dryness >= 100f)
{
dryness = 100f;
}
}
if (food >= 1)
{
foodText.text = "Food " + food + "/100";
}
else
{
foodText.text = "Dead";
}
if (warmth >= 1f)
{
warmthText.text = "Warmth " + warmth.ToString("F1") + "/100";
}
else
{
warmthText.text = "Dead";
}
if (dryness >= 1f)
{
drynessText.text = "Dryness " + dryness.ToString("F1") + "/100";
}
else
{
drynessText.text = "Dead";
}
if (dryness <= 0f)
{
dryness = 0f;
}
if (warmth <= 0f)
{
warmth = 0f;
}
if (isSheltered)
{
warmth += Time.deltaTime * 0.5f;
if (warmth >= 100f)
{
warmth = 100f;
}
dryness += Time.deltaTime * 0.5f;
if (dryness >= 100f)
{
dryness = 100f;
}
shelteredText.text = "Sheltered";
shelteredText.color = Color.green;
}
if (!isSheltered)
{
shelteredText.text = "Not Sheltered";
shelteredText.color = Color.red;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == shelterTag)
{
isSheltered = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == shelterTag)
{
isSheltered = false;
}
}
}