/
arti4
/
Diplom
Обзор
Документация
Войти
/
arti4
/
Diplom
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Scripts/Buildings/Radars/FloatingText.cs
48 строк
1 KB
arti4
Загрузка всех скриптов
17 май 2026, 09:08
Верифицирован
17 май 2026, 09:08
cc2e1cd
Код
Авторство
О чём код?
using UnityEngine; using TMPro; using System.Collections; public class FloatingText : MonoBehaviour { private TMP_Text textMesh; private float duration = 2f; private float floatSpeed = 1f; private float fadeSpeed = 1f; void Awake() { textMesh = GetComponentInChildren<TMP_Text>(); } public void Initialize(float textDuration, float floatSpeed) { this.duration = textDuration; this.floatSpeed = floatSpeed; this.fadeSpeed = 1f / textDuration; StartCoroutine(FloatAndFade()); } IEnumerator FloatAndFade() { float elapsed = 0f; Color startColor = textMesh != null ? textMesh.color : Color.white; while (elapsed < duration) { transform.position += Vector3.up * floatSpeed * Time.deltaTime; if (textMesh != null) { Color color = textMesh.color; color.a = Mathf.Lerp(1f, 0f, elapsed / duration); textMesh.color = color; } elapsed += Time.deltaTime; yield return null; } Destroy(gameObject); } }