-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadingScreenTips.cs
62 lines (54 loc) · 1.43 KB
/
LoadingScreenTips.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Text))]
public class LoadingScreenTips : MonoBehaviour
{
Text textBox;
[Range(0, 100)]
public int jokeChance;
[Tooltip("Set this false to not show a joke")]
public bool showJoke;
[TextArea(1, 2)]
public string[] loadingTipsSerious;
[TextArea(1, 2)]
public string[] loadingTipsJoke;
public float delay;
// Start is called before the first frame update
void OnEnable()
{
textBox = GetComponent<Text>();
PickTip();
}
public string RandomTip()
{
string s = loadingTipsSerious[Random.Range(0, loadingTipsSerious.Length)];
return s;
}
public string RandomJoke()
{
string s = loadingTipsJoke[Random.Range(0, loadingTipsJoke.Length)];
return s;
}
public void PickTip()
{
int roll = Random.Range(0, 100);
if (roll <= jokeChance && showJoke)
{
StartCoroutine(ShowTip(RandomJoke(),delay));
}else{
StartCoroutine(ShowTip(RandomTip(), delay));
}
}
public IEnumerator ShowTip(string tip,float del)
{
textBox.text = tip;
if(del==0)
{
yield break;
}
yield return new WaitForSecondsRealtime(delay); //using Realtime in case the user pauses timeScale.
PickTip();
}
}