using System.Collections; using System.Collections.Generic; using UnityEngine; public class UranusDeath : 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; private Renderer _planetRenderer; private Material _planetMat; private Texture2D _originalTexture; void Start() { _planetRenderer = GetComponent(); if (_planetRenderer == null) _planetRenderer = GetComponentInChildren(); if (_planetRenderer != null) { _planetMat = _planetRenderer.material; _originalTexture = (Texture2D)_planetMat.GetTexture("_BaseMap"); } } public void ResetTexture() { troposphereLevel = 1f; stratosphereLevel = 1f; thermosphereLevel = 1f; if (_planetMat != null && _originalTexture != null) _planetMat.SetTexture("_BaseMap", _originalTexture); } void Update() { if (_planetMat == null) return; UpdatePlanetTexture(); } void UpdatePlanetTexture() { float worst = Mathf.Min(troposphereLevel, stratosphereLevel, thermosphereLevel); if (worst >= 1f) { if (_originalTexture != null) _planetMat.SetTexture("_BaseMap", _originalTexture); return; } Texture2D tex = worst <= 0f ? deadTexture : GetPlanetTexture(worst); if (tex != null) _planetMat.SetTexture("_BaseMap", tex); } Texture2D GetPlanetTexture(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; } }