Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2025
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. public class AppeasementMeter : MonoBehaviour
  5. {
  6. public float maxAppeasement = 100;
  7. public float appeasement;
  8.  
  9. public Slider slider;
  10.  
  11. public float appeasementDrainRate = 1;
  12. public enum Mood { Praised, Pleased, Indifferent, Displeased, Angered }
  13. public Mood currentMood;
  14.  
  15. public GameObject praised;
  16. public GameObject pleased;
  17. public GameObject indifferent;
  18. public GameObject displeased;
  19. public GameObject angered;
  20.  
  21. // Skybox Settings
  22. public Material skyboxMaterial;
  23. public float initialAtmosphereThickness = 1f;
  24. public float targetAtmosphereThickness = 5f;
  25. public float initialExposure = 1.3f;
  26. public float targetExposure = 5.9f;
  27.  
  28. // Light Settings
  29. public Light directionalLight;
  30. public float initialTemperature = 5000f;
  31. public float targetTemperature = 1500f;
  32. public float initialIntensity = 1f;
  33. public float targetIntensity = 0.5f;
  34.  
  35. // Fog Settings
  36. public Color initialFogColor = new Color(0.8f, 0.85f, 0.85f);
  37. public Color targetFogColor = new Color(0f, 0f, 0f);
  38.  
  39. public float effectStartThreshold = 20f; // Adjustable value for when effects start
  40.  
  41. private float lerpTime = 0f;
  42.  
  43. // Reference to DayNightCycle for starting ApocalypseMode
  44. public DayNightCycle dayNightCycle;
  45.  
  46. public bool apocalypseStarted = false;
  47.  
  48. void Start()
  49. {
  50. appeasement = maxAppeasement;
  51.  
  52. if (skyboxMaterial != null)
  53. {
  54. skyboxMaterial.SetFloat("_AtmosphereThickness", initialAtmosphereThickness);
  55. skyboxMaterial.SetFloat("_Exposure", initialExposure);
  56. }
  57.  
  58. if (directionalLight != null)
  59. {
  60. directionalLight.colorTemperature = initialTemperature;
  61. directionalLight.intensity = initialIntensity;
  62. }
  63.  
  64. RenderSettings.fogColor = initialFogColor;
  65. }
  66.  
  67. void Update()
  68. {
  69. if (appeasement >= 80)
  70. {
  71. currentMood = Mood.Praised;
  72. appeasementDrainRate = 0.30f;
  73. }
  74. else if (appeasement >= 60)
  75. {
  76. currentMood = Mood.Pleased;
  77. appeasementDrainRate = 0.50f;
  78. }
  79. else if (appeasement >= 40)
  80. {
  81. currentMood = Mood.Indifferent;
  82. appeasementDrainRate = 1f;
  83. }
  84. else if (appeasement >= 20)
  85. {
  86. currentMood = Mood.Displeased;
  87. appeasementDrainRate = 1.25f;
  88. }
  89. else
  90. {
  91. currentMood = Mood.Angered;
  92. appeasementDrainRate = 1.5f;
  93. lerpTime += Time.deltaTime * appeasementDrainRate;
  94. }
  95.  
  96. UpdateSprites();
  97.  
  98.  
  99. slider.value = Mathf.Lerp(slider.value, appeasement, Time.deltaTime * 1f);
  100.  
  101. SetAppeasement(appeasement);
  102.  
  103. if (appeasement <= 0 && apocalypseStarted == false)
  104. {
  105. if (dayNightCycle != null)
  106. {
  107. dayNightCycle.StartApocalypseMode();
  108. dayNightCycle.apocalypseActive = true; // Ensures that Apocalypse Mode is marked as active
  109. apocalypseStarted = true;
  110. Debug.Log("Apocalypse Mode started: apocalypseActive is set to true.");
  111. }
  112. }
  113.  
  114. // Updates appeasement after the checks above
  115. appeasement -= Time.deltaTime * appeasementDrainRate;
  116. appeasement = Mathf.Clamp(appeasement, 0, maxAppeasement);
  117.  
  118.  
  119. if (appeasement <= effectStartThreshold)
  120. {
  121. float progression = Mathf.InverseLerp(effectStartThreshold, 0f, appeasement);
  122.  
  123. skyboxMaterial.SetFloat("_AtmosphereThickness", Mathf.Lerp(initialAtmosphereThickness, targetAtmosphereThickness, progression));
  124. skyboxMaterial.SetFloat("_Exposure", Mathf.Lerp(initialExposure, targetExposure, progression));
  125.  
  126. directionalLight.colorTemperature = Mathf.Lerp(initialTemperature, targetTemperature, progression);
  127. directionalLight.intensity = Mathf.Lerp(initialIntensity, targetIntensity, progression);
  128.  
  129. RenderSettings.fogColor = Color.Lerp(initialFogColor, targetFogColor, progression);
  130. }
  131. }
  132.  
  133. void UpdateSprites()
  134. {
  135. praised.SetActive(currentMood == Mood.Praised);
  136. pleased.SetActive(currentMood == Mood.Pleased);
  137. indifferent.SetActive(currentMood == Mood.Indifferent);
  138. displeased.SetActive(currentMood == Mood.Displeased);
  139. angered.SetActive(currentMood == Mood.Angered);
  140. }
  141.  
  142. void SetAppeasement(float appeasement)
  143. {
  144. slider.value = appeasement;
  145. }
  146.  
  147. public void ResetWeatherAndLighting()
  148. {
  149. if (skyboxMaterial != null)
  150. {
  151. skyboxMaterial.SetFloat("_AtmosphereThickness", initialAtmosphereThickness);
  152. skyboxMaterial.SetFloat("_Exposure", initialExposure);
  153. }
  154.  
  155. if (directionalLight != null)
  156. {
  157. directionalLight.colorTemperature = initialTemperature;
  158. directionalLight.intensity = initialIntensity;
  159. }
  160.  
  161. RenderSettings.fogColor = initialFogColor;
  162.  
  163. apocalypseStarted = false;
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement