ClientServer/Client/Assets/Scripts/Content/FloatingDamageText.cs
TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

72 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using DG.Tweening;
public class FloatingDamageText : MonoBehaviour
{
private TextMeshPro textMesh;
private float speed;
private readonly WaitForSeconds zeroFive = new WaitForSeconds(0.5f);
private readonly WaitForSeconds two = new WaitForSeconds(2.0f);
public float MaxWaitTime = 5.0f;
private void Awake()
{
speed = Random.Range(1f, 3.5f);
textMesh = GetComponent<TextMeshPro>();
}
private void OnEnable()
{
StartCoroutine(MoveNoise());
transform.localScale = Vector3.zero;
transform.DOScale(Vector3.one * 0.125f, 0.75f).SetEase(Ease.OutBack);
}
public TextMeshPro GetText() => textMesh;
private void Update()
{
if (Player.Instance != null)
{
transform.forward = (transform.position - Player.Instance.GetPlayerFirstPersonCameraPosition()).normalized;
}
}
private IEnumerator MoveNoise()
{
float time = 0;
float randXDir = Random.Range(-1f, 1f);
while (time < 1)
{
transform.localPosition += new Vector3(randXDir, 0, 0) * (speed * Time.deltaTime);
transform.position += Vector3.up * (speed * Time.deltaTime);
textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, time < 0.50f ? 1.0f : Mathf.Lerp(1.0f, 0f, (time - 0.50f) / 0.50f));
time += Time.deltaTime / MaxWaitTime;
yield return null;
}
textMesh.color = Color.clear;
yield return zeroFive;
ResetPopUp();
}
private void ResetPopUp()
{
StopAllCoroutines();
transform.position = Vector3.zero;
textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, 1.0f);
gameObject.SetActive(false);
}
private void OnDisable()
{
ResetPopUp();
}
}