31 lines
752 B
C#
31 lines
752 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
|
|
public class TextFadeController : MonoBehaviour
|
|
{
|
|
[SerializeField] public TextMeshPro text;
|
|
[SerializeField] float dieTime = 1.0f;
|
|
|
|
[SerializeField] public Color baseColor = Color.white;
|
|
|
|
[HideInInspector] float alpha = 1.0f;
|
|
[HideInInspector] float startTime = -1.0f;
|
|
|
|
private void Awake()
|
|
{
|
|
startTime = Time.time;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void LateUpdate()
|
|
{
|
|
alpha = Mathf.Max(0.0f, 1.0f - (Time.time - startTime) / dieTime);
|
|
text.color = new Color(baseColor.r, baseColor.g, baseColor.b, alpha);
|
|
if (alpha == 0.0f) {
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|