Repository navigation
Expand file tree
/
Copy pathNotificationSystem.cs
More file actions
62 lines (51 loc) · 1.69 KB
/
Copy pathNotificationSystem.cs
File metadata and controls
62 lines (51 loc) · 1.69 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class NotificationSystem : MonoBehaviour
{
[Header("Values")]
public float FadeoutSpeed;
[Header("References")]
public GameObject TextPrefab;
public GameObject Content;
public GameObject NotificationUI;
void Update()
{
JumpToBottom();
NotificationsFade();
}
void SendNotification(string msg, Color col)
{
GameObject clone1 = (GameObject)Instantiate(TextPrefab, Content.transform.position, Quaternion.identity);
JumpToBottom();
NotificationsAlphaReset();
clone1.transform.SetParent(Content.transform);
clone1.GetComponent<Text>().color = col;
clone1.GetComponent<Text>().text = msg;
JumpToBottom();
}
void NotificationsAlphaReset()
{
foreach (Transform notification in Content.transform)
{
Color resetedCol = notification.GetComponent<Text>().color;
resetedCol.a = 1;
notification.GetComponent<Text>().color = resetedCol;
}
}
void NotificationsFade()
{
//Debug.Log("Called fade");
foreach (Transform notification in Content.transform)
{
Color fadedCol = notification.GetComponent<Text>().color;
fadedCol.a -= 0.1f * Time.deltaTime * FadeoutSpeed;
notification.GetComponent<Text>().color = fadedCol;
}
}
void JumpToBottom()
{
NotificationUI.GetComponent<ScrollRect>().verticalScrollbar.gameObject.GetComponent<Scrollbar>().value = 0;
}
}