-
Notifications
You must be signed in to change notification settings - Fork 1
/
ButtonFader.cs
61 lines (54 loc) · 1.21 KB
/
ButtonFader.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
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ButtonFader : MonoBehaviour {
public bool faded = false;
Image buttonImage;
Text txt;
Color buttonColor;
Color textColor;
bool startFade = false;
float smooth = 0;
bool initialized = false;
void Start()
{
Initialize();
}
void Initialize()
{
startFade = false;
faded = false;
buttonImage = GetComponent<Image>();
buttonColor = buttonImage.color;
if (GetComponentInChildren<Text>())
{
txt = GetComponentInChildren<Text>();
textColor = txt.color;
}
initialized = true;
}
void Update()
{
if (startFade)
{
Fade(smooth);
if (buttonColor.a > 0.9)
faded = true;
}
}
public void Fade(float rate)
{
if (!initialized)
Initialize();
smooth = rate;
startFade = true;
buttonColor.a += rate;
buttonImage = GetComponent<Image>();
buttonImage.color = buttonColor;
if (txt)
{
textColor.a += rate;
txt.color = textColor;
}
}
}