-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnouncer.cs
53 lines (46 loc) · 893 Bytes
/
Announcer.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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(TextMesh))]
public class Announcer : MonoBehaviour {
public float messageShowTime;
float messageTime;
static Announcer instance;
TextMesh mesh;
Queue<string> messageQueue;
public static Announcer Instance
{
get
{
return instance;
}
}
void Awake()
{
if (instance != null)
{
Debug.LogWarning("Announcer instance already created.");
Destroy(gameObject);
}
instance = this;
mesh = GetComponent<TextMesh>();
messageQueue = new Queue<string>();
}
public void ShowMessage(string message)
{
messageQueue.Enqueue( message );
}
void Update()
{
if (messageTime <= Time.time)
{
if (messageQueue.Count > 0)
{
messageTime = Time.time + messageShowTime;
mesh.text = messageQueue.Dequeue();
}
else
mesh.text = "";
}
}
}