-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandomPopupText.cs
100 lines (86 loc) · 2.5 KB
/
RandomPopupText.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class RandomPopupText : MonoBehaviour
{
Text uiText;
Color startColor = new Color(255, 255, 255, 0);
Color endColor = new Color(255, 255, 255, 1);
float maxX = Screen.width - 250;
float maxY = Screen.height - 50;
float offsetX = 125;
float offsetY = 50;
string[] sentences = new string[]
{
"Why",
"I can't believe you've done this",
"Taxa mica",
"I can see the bone",
"My pelvis!",
"I need iodine!",
"There goes the neighbourhood...",
"My car!",
"Not again...",
"One day to retirement...",
"You will pay for this!",
"Is that an ogre?",
"Is that a plane?",
"It's a donkey!!!",
"Obamacare, here I come!",
"Oh no.",
"RUN, RON!!!",
"Darling, get the kids!!",
"We have a huge problem...",
"What's that smell?",
"Am I on a prank show..?",
"Huston, we have a problem!",
"Godzilla!!!!!!",
"What in OBLIVION is THAT!?",
"I can see my life flashing before my eyes",
"Aw man, I LOVE Shingeki no kyojin!",
"HELP",
"help",
"Help",
"Help!",
"Aaaaaa",
"Hurg",
"No",
"That was priceless",
};
void Start()
{
uiText = GetComponent<Text>();
uiText.text = sentences[Random.Range(0, sentences.Length)];
uiText.fontSize = Random.Range(10, 20);
var posX = Random.Range(offsetX, maxX);
var posY = Random.Range(offsetY, maxY);
uiText.gameObject.transform.position = new Vector2(posX, posY);
StartCoroutine(_Popup());
}
private IEnumerator _Popup()
{
yield return StartCoroutine(FadeIn());
yield return new WaitForSeconds(2);
yield return StartCoroutine(FadeOut());
}
private IEnumerator FadeIn()
{
float timestamp = 0;
do
{
timestamp += Time.deltaTime;
uiText.color = Color.Lerp(startColor, endColor, timestamp);
yield return new WaitForEndOfFrame();
} while (uiText.color != endColor);
}
private IEnumerator FadeOut()
{
float timestamp = 0;
do
{
timestamp += Time.deltaTime;
uiText.color = Color.Lerp(endColor, startColor, timestamp);
yield return new WaitForEndOfFrame();
} while (uiText.color != startColor);
}
}