-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMessageBehavior.cs
More file actions
44 lines (36 loc) · 1.05 KB
/
MessageBehavior.cs
File metadata and controls
44 lines (36 loc) · 1.05 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using system.generic;
public class MessageBehavior : MonoBehaviour {
public Text uiText;
private Vector3 showPosition = new Vector3 (0, 240f, 0);
private Vector3 hidePosition = new Vector3 (0, 330f, 0);
private Vector3 desiredPosition;
private void Awake () {
desiredPosition = hidePosition;
}
private void Update () {
transform.localPosition = Vector3.Lerp (transform.localPosition, desiredPosition, 6F * Time.deltaTime);
}
public void ShowMessage (string message) {
HideMessage ();
desiredPosition = showPosition;
uiText.text = message;
if (DelayCoroutine != null) {
StopCoroutine (DelayCoroutine);
}
DelayCoroutine = StartCoroutine (DelayHideMessage ());
}
Coroutine DelayCoroutine;
IEnumerator DelayHideMessage () {
yield return new WaitForSeconds (2f);
HideMessage ();
DelayCoroutine = null;
}
void HideMessage () {
desiredPosition = hidePosition;
uiText.text = "";
}
}