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