using System; using UnityEngine; using UnityEngine.UI; [Serializable] public class PlayerVitalsExample_JS : MonoBehaviour { private GameObject uniStormSystem; private UniStormWeatherSystem_JS uniStormSystemScript; public int food; public float dryness; public float warmth; private bool isSheltered; private bool foodCalculated; public string shelterTag; public Text foodText; public Text drynessText; public Text warmthText; public Text shelteredText; public PlayerVitalsExample_JS() { food = 100; dryness = 100f; warmth = 100f; shelterTag = "Shelter"; } public virtual void Awake() { uniStormSystem = GameObject.Find("UniStormSystemEditor"); uniStormSystemScript = (UniStormWeatherSystem_JS)uniStormSystem.GetComponent(typeof(UniStormWeatherSystem_JS)); } public virtual void Start() { if (uniStormSystem == null) { Debug.LogError("Null Reference: You must have the UniStorm Editor in your scene and named 'UniStormSystemEditor'. Make sure your C# UniStorm Editor has this name. "); } } public virtual 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.ToString() + "/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; } } public virtual void OnTriggerEnter(Collider other) { if (other.gameObject.tag == shelterTag) { isSheltered = true; } } public virtual void OnTriggerExit(Collider other) { if (other.gameObject.tag == shelterTag) { isSheltered = false; } } public virtual void Main() { } }