Files
2026-05-29 18:21:53 +03:00

130 lines
3.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MarsDeath : MonoBehaviour
{
[Header("Òåêñòóðè")]
public Texture2D mars100;
public Texture2D mars70;
public Texture2D mars50;
public Texture2D mars30;
public Texture2D mars0;
[Header("Òåðìîñôåðà")]
public Texture2D thermo100;
public Texture2D thermo70;
public Texture2D thermo50;
public Texture2D thermo30;
public Texture2D thermo0;
[Header("Ìåðòâà ïëàíåòà")]
public Texture2D deadTexture;
[Range(0f, 1f)]
public float troposphereLevel = 1f;
[Range(0f, 1f)]
public float mesosphereLevel = 1f;
[Range(0f, 1f)]
public float thermosphereLevel = 1f;
private Renderer planetRenderer;
private Material mat;
private float prevTropo = -1f;
private float prevMeso = -1f;
private float prevThermo = -1f;
private bool deadApplied = false;
private Texture2D originalTexture;
void Start()
{
planetRenderer = GetComponent<Renderer>();
if (planetRenderer == null)
planetRenderer = GetComponentInChildren<Renderer>();
if (planetRenderer != null)
{
mat = planetRenderer.material;
originalTexture = (Texture2D)mat.GetTexture("_BaseMap");
}
}
public void ResetTexture()
{
troposphereLevel = 1f;
mesosphereLevel = 1f;
thermosphereLevel = 1f;
prevTropo = -1f;
prevMeso = -1f;
prevThermo = -1f;
deadApplied = false;
if (mat != null && originalTexture != null)
mat.SetTexture("_BaseMap", originalTexture);
}
void Update()
{
if (mat == null) return;
if ((mesosphereLevel <= 0f || thermosphereLevel <= 0f) && !deadApplied)
{
deadApplied = true;
if (deadTexture != null)
mat.SetTexture("_BaseMap", deadTexture);
return;
}
if (Mathf.Approximately(troposphereLevel, prevTropo) &&
Mathf.Approximately(mesosphereLevel, prevMeso) &&
Mathf.Approximately(thermosphereLevel, prevThermo)) return;
prevTropo = troposphereLevel;
prevMeso = mesosphereLevel;
prevThermo = thermosphereLevel;
UpdateTexture();
}
void UpdateTexture()
{
if (thermosphereLevel < 1f)
{
SetTexture(GetThermoTexture(thermosphereLevel));
return;
}
if (troposphereLevel < 1f)
{
SetTexture(GetTropoTexture(troposphereLevel));
return;
}
}
void SetTexture(Texture2D tex)
{
if (tex != null)
mat.SetTexture("_BaseMap", tex);
}
Texture2D GetTropoTexture(float level)
{
if (level >= 0.7f) return mars100;
else if (level >= 0.5f) return mars70;
else if (level >= 0.3f) return mars50;
else if (level > 0f) return mars30;
else return mars0;
}
Texture2D GetThermoTexture(float level)
{
if (level >= 0.7f) return thermo100;
else if (level >= 0.5f) return thermo70;
else if (level >= 0.3f) return thermo50;
else if (level > 0f) return thermo30;
else return thermo0;
}
}