miepzerino
2023-12-15 24253ea93a51232da89a429aa4964578446bca44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
 
public class HealthText : MonoBehaviour
{
    public Vector3 moveSpeed = new Vector3(0, 75, 0);
 
    public float timeToFade = 1f;
    public float startToFade = 1f;
    private float timeElapsed = 0f;
 
    RectTransform textTransform;
 
    TextMeshProUGUI textMeshPro;
 
    private void Awake()
    {
        textTransform = GetComponent<RectTransform>();
        textMeshPro = GetComponent<TextMeshProUGUI>();
    }
 
    private void Update()
    {
        timeElapsed += Time.deltaTime;
        if (timeElapsed >= startToFade)
        {
            textMeshPro.alpha = (1 - ((timeElapsed - startToFade) / timeToFade));
            if (timeElapsed >= (startToFade + timeToFade))
            {
                Destroy(gameObject);
            }
        }
        textTransform.position += moveSpeed * Time.deltaTime;
    }
}