123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- using TMPro;
- namespace KairoEngine.UI
- {
- public class FloatingValueUi : MonoBehaviour
- {
- public TextMeshProUGUI textMesh;
- public RectTransform rectTransform;
- public float lifetime = 1f;
- private Vector3 pos;
- private float counter = 0f;
- private float positionOffset;
- public void Setup(Vector3 position, string text, float positionOffset, float lifetime, float fontSize)
- {
- textMesh.text = text;
- pos = new Vector3(position.x, position.y + 2.5f, position.z);
- this.lifetime = lifetime;
- this.positionOffset = positionOffset;
- textMesh.fontSize = fontSize;
- }
- public void Update()
- {
- textMesh.enabled = true;
- if (pos != null && rectTransform != null)
- {
- pos.y += positionOffset * Time.deltaTime;
- Vector3 screenPos = Camera.main.WorldToScreenPoint(pos);
- rectTransform.position = screenPos;
- }
- counter += Time.deltaTime;
- if(counter > lifetime)
- {
- Destroy(gameObject);
- }
- if(counter > lifetime/2)
- {
- float a = textMesh.color.a - (textMesh.color.a * (lifetime * 2)) * Time.deltaTime;
- Color c = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, a);
- textMesh.color = c;
- }
-
- }
- }
- }
|