-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatingText.cs
More file actions
33 lines (27 loc) · 839 Bytes
/
FloatingText.cs
File metadata and controls
33 lines (27 loc) · 839 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
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class FloatingText : MonoBehaviour {
public Vector3 worldPosition;
public float scrollSpeed;
public float fadeDuration;
public float fadeOffset;
private float x;
private TextMeshProUGUI tmp;
private Color color;
private float initialAlpha;
void Start()
{
tmp = GetComponent<TextMeshProUGUI>();
color = tmp.color;
initialAlpha = color.a;
}
// Update is called once per frame
void Update () {
x += Time.deltaTime;
transform.position = Camera.main.WorldToScreenPoint(worldPosition) + x * scrollSpeed * Vector3.up;
color.a = Mathf.Min(initialAlpha, -(1.0f / fadeDuration) * (x - fadeOffset) + initialAlpha);
tmp.color = color;
}
}