using UnityEngine; public class EnviroPuddle : MonoBehaviour { public GameObject puddleObject; [HideInInspector] public bool isRaining; public bool useWaveAnimation; public Vector2 waveSpeed; public bool useRipples; public Texture2D[] RippleFrames; public float RippleAnimationSpeed = 30f; private MeshRenderer mRenderer; private Material[] mats; private float curWaveSpeedx; private float curWaveSpeedy; public float maxFloodHeight = 0.1f; public float minFloodHeight = -0.1f; [HideInInspector] public float floodVal = 0.3f; private float curFlood; private float lastUpdate; private void Start() { mRenderer = puddleObject.GetComponent(); mats = mRenderer.materials; } public float Remap(float value, float from1, float to1, float from2, float to2) { return (value - from1) / (to1 - from1) * (to2 - from2) + from2; } private void Update() { mats = mRenderer.materials; floodVal = EnviroSky.instance.Weather.wetness; if (floodVal <= 0.1f) { isRaining = false; } else { isRaining = true; } if (useRipples && isRaining) { int num = (int)(Time.time * RippleAnimationSpeed); num %= RippleFrames.Length; for (int i = 0; i < mats.Length; i++) { mats[i].SetTexture("_Ripple", RippleFrames[num]); } } else { for (int j = 0; j < mats.Length; j++) { mats[j].SetTexture("_Ripple", null); } } if (isRaining) { puddleObject.SetActive(true); if (useWaveAnimation) { Vector2 value = default(Vector2); value.x = Time.time * waveSpeed.x; value.y = Time.time * waveSpeed.y; for (int k = 0; k < mats.Length; k++) { mats[k].SetTextureOffset("_WetNormal", value); } } for (int l = 0; l < mats.Length; l++) { mats[l].SetFloat("_Raining", floodVal); } } else { puddleObject.SetActive(false); for (int m = 0; m < mats.Length; m++) { mats[m].SetFloat("_Raining", -0.01f); } } float y = Remap(floodVal, 0f, 1f, minFloodHeight, maxFloodHeight); puddleObject.transform.localPosition = new Vector3(puddleObject.transform.localPosition.x, y, puddleObject.transform.localPosition.z); } }