using JetBrains.Annotations; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class ComboTextBehavior : MonoBehaviour { private static Vector2 SpawningRelativePosition { get { return new Vector2(0.0f, -160.0f); } } private static Vector2 FadeoutRelativePosition { get { return new Vector2(0.0f, -60.0f); } } private const float Lifetime = 0.8f; 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, 1.0f); gameObject.GetComponent().anchorMax = new Vector2(0.5f, 1.0f); } // 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(1.0f, 1.5f, currentAlpha); gameObject.transform.localScale = new Vector3(scale, scale, scale); float currentPosAlpha = Mathf.InverseLerp(0.0f, Lifetime, Age); float PosY = Mathf.Lerp(SpawningRelativePosition.y, FadeoutRelativePosition.y, currentPosAlpha); gameObject.GetComponent().anchoredPosition = new Vector2(SpawningRelativePosition.x, PosY); } } // set the number of combo for display public void SetComboNumber(int num) { gameObject.GetComponent().text = "Combo × " + num; } }