using JetBrains.Annotations; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class CriticalTextBehavior : MonoBehaviour { private const float Lifetime = 1.0f; private const float FadeinThreshold = 0.1f; private float Age = 0.0f; // Start is called before the first frame update void Start() { gameObject.GetComponent().color = new Color(1.0f, 1.0f, 1.0f, 0.0f); gameObject.GetComponent().anchorMin = new Vector2(0.5f, 1f); gameObject.GetComponent().anchorMax = new Vector2(0.5f, 1f); } // Update is called once per frame void Update() { Age += Time.deltaTime; if (Age > Lifetime) { Destroy(gameObject); } else { float currentAlpha = (Age < FadeinThreshold) ? Mathf.InverseLerp(0.0f, FadeinThreshold, Age) : Mathf.InverseLerp(Lifetime, FadeinThreshold, Age); gameObject.GetComponent().color = new Color(1.0f, 1.0f, 1.0f, currentAlpha); float scale = Mathf.Lerp(0.8f, 1.0f, currentAlpha); gameObject.transform.localScale = new Vector3(scale, scale, scale); float currentPosAlpha = Mathf.InverseLerp(0.0f, Lifetime, Age); } } }