-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextMeshFadeAlpha.cs
More file actions
35 lines (31 loc) · 883 Bytes
/
TextMeshFadeAlpha.cs
File metadata and controls
35 lines (31 loc) · 883 Bytes
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
using TMPro;
using UnityEngine;
namespace uMMORPG
{
[RequireComponent(typeof(TextMeshPro))]
public class TextMeshFadeAlpha : MonoBehaviour
{
public TextMeshPro textMesh;
public float delay = 0;
public float duration = 1;
float perSecond;
float startTime;
void Start()
{
// calculate by how much to fade per second
perSecond = textMesh.color.a / duration;
// calculate start time
startTime = Time.time + delay;
}
void Update()
{
if (Time.time >= startTime)
{
// fade all text meshes (in children too in case of shadows etc.)
Color color = textMesh.color;
color.a -= perSecond * Time.deltaTime;
textMesh.color = color;
}
}
}
}