| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using JetBrains.Annotations;
- using System.Collections;
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- public class AddLifeTextScript : MonoBehaviour
- {
- public Image HeartImage;
- private static Vector2 SpawningRelativePosition
- {
- get
- {
- return new Vector2(300f, -310.0f);
- }
- }
- private static Vector2 FadeoutRelativePosition
- {
- get
- {
- return new Vector2(300f, -210.0f);
- }
- }
- private const float Lifetime = 2f;
- private const float FadeinThreshold = 0.1f;
- private float Age = 0.0f;
- // Start is called before the first frame update
- void Start()
- {
- gameObject.GetComponent<TextMeshProUGUI>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
- gameObject.GetComponent<RectTransform>().anchorMin = new Vector2(0f, 1.0f);
- gameObject.GetComponent<RectTransform>().anchorMax = new Vector2(0f, 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<TextMeshProUGUI>().color = new Color(1.0f, 1.0f, 1.0f, currentAlpha);
- HeartImage.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<RectTransform>().anchoredPosition = new Vector2(SpawningRelativePosition.x, PosY);
- }
- }
- // set the number of combo for display
- public void SetComboNumber(int num)
- {
- gameObject.GetComponent<TextMeshProUGUI>().text = "Combo × " + num;
- }
- }
|