using System.Collections; using System.Collections.Generic; using UnityEngine; public class JupiterDeath : MonoBehaviour { [Header("Текстури тропосфери")] public Texture2D tropo100; public Texture2D tropo70; public Texture2D tropo50; public Texture2D tropo30; public Texture2D tropo0; public Texture2D deadTexture; [Range(0f, 1f)] public float troposphereLevel = 1f; public float stratosphereLevel = 1f; public float thermosphereLevel = 1f; public float exosphereLevel = 1f; private Renderer planetRenderer; private Material mat; private float prevLevel = -1f; private Texture2D originalTexture; void Start() { planetRenderer = GetComponent(); if (planetRenderer == null) planetRenderer = GetComponentInChildren(); if (planetRenderer != null) { mat = planetRenderer.material; originalTexture = (Texture2D)mat.GetTexture("_BaseMap"); } } public void ResetTexture() { troposphereLevel = 1f; stratosphereLevel = 1f; thermosphereLevel = 1f; exosphereLevel = 1f; prevLevel = -1f; if (mat != null && originalTexture != null) { mat.SetTexture("_BaseMap", originalTexture); mat.SetTexture("_BaseMap2", originalTexture); } } void Update() { if (mat == null) return; UpdateTexture(); } void UpdateTexture() { float worst = Mathf.Min(troposphereLevel, stratosphereLevel, thermosphereLevel, exosphereLevel); if (worst >= 1f) { if (mat != null && originalTexture != null) { mat.SetTexture("_BaseMap", originalTexture); mat.SetTexture("_BaseMap2", originalTexture); } return; } Texture2D tex = worst <= 0f ? deadTexture : GetTexture(worst); if (tex != null) { mat.SetTexture("_BaseMap", tex); mat.SetTexture("_BaseMap2", tex); } } Texture2D GetTexture(float level) { if (level >= 0.7f) return tropo100; else if (level >= 0.5f) return tropo70; else if (level >= 0.3f) return tropo50; else if (level > 0f) return tropo30; else return tropo0; } }