-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFloatingTextFactory.cs
51 lines (38 loc) · 1.45 KB
/
FloatingTextFactory.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class FloatingTextFactory : MonoBehaviour {
public TMP_FontAsset font;
public int size = 32;
private static FloatingTextFactory instance;
void Awake()
{
if (instance == null)
{
instance = this;
}
}
public static void Create(string text, Vector3 position, Color color, int size = 32, float duration = 2.0f, float scrollSpeed = 50.0f)
{
Create(text, position, color, size, duration, scrollSpeed, duration / 2.0f, duration / 2.0f);
}
public static void Create(string text, Vector3 position, Color color, int size, float duration, float scrollSpeed, float fadeDuration, float fadeOffset)
{
GameObject go = new GameObject("FloatingText_" + text);
TextMeshProUGUI tmp = go.AddComponent<TextMeshProUGUI>();
tmp.font = instance.font;
tmp.text = text;
tmp.fontSize = size;
tmp.alignment = TextAlignmentOptions.Center;
tmp.enableWordWrapping = true;
tmp.color = color;
FloatingText floatingText = go.AddComponent<FloatingText>();
floatingText.worldPosition = position;
floatingText.scrollSpeed = scrollSpeed;
floatingText.fadeDuration = fadeDuration;
floatingText.fadeOffset = fadeOffset;
go.transform.SetParent(instance.transform);
Destroy(go, duration);
}
}