66 lines
1.6 KiB
C#
66 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MercuryDeath : MonoBehaviour
|
|
{
|
|
[Header("Òåêñòóðè")]
|
|
public Texture2D mercury100;
|
|
public Texture2D mercury70;
|
|
public Texture2D mercury50;
|
|
public Texture2D mercury30;
|
|
public Texture2D mercury0;
|
|
|
|
[Header("Ìåðòâà ïëàíåòà")]
|
|
public Texture2D deadTexture;
|
|
|
|
[Range(0f, 1f)]
|
|
public float exosphereLevel = 1f;
|
|
|
|
private Renderer planetRenderer;
|
|
private Material mat;
|
|
private float prevLevel = -1f;
|
|
|
|
void Start()
|
|
{
|
|
planetRenderer = GetComponent<Renderer>();
|
|
if (planetRenderer == null)
|
|
planetRenderer = GetComponentInChildren<Renderer>();
|
|
if (planetRenderer != null)
|
|
mat = planetRenderer.material;
|
|
}
|
|
|
|
public void ResetTexture()
|
|
{
|
|
exosphereLevel = 1f;
|
|
prevLevel = -1f;
|
|
if (mat != null && mercury100 != null)
|
|
mat.SetTexture("_BaseMap", mercury100);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (mat == null) return;
|
|
if (Mathf.Approximately(exosphereLevel, prevLevel)) return;
|
|
prevLevel = exosphereLevel;
|
|
UpdateTexture();
|
|
}
|
|
|
|
void UpdateTexture()
|
|
{
|
|
Texture2D tex = exosphereLevel <= 0f ? deadTexture : GetTexture(exosphereLevel);
|
|
if (tex != null)
|
|
mat.SetTexture("_BaseMap", tex);
|
|
}
|
|
|
|
Texture2D GetTexture(float level)
|
|
{
|
|
if (level >= 0.7f) return mercury100;
|
|
else if (level >= 0.5f) return mercury70;
|
|
else if (level >= 0.3f) return mercury50;
|
|
else if (level > 0f) return mercury30;
|
|
else return mercury0;
|
|
}
|
|
|
|
}
|