-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlphaFadeOut.cs
49 lines (41 loc) · 1.18 KB
/
AlphaFadeOut.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
// AlphaFadeOut.cs
// Last edited 7:43 PM 04/15/2015 by Aaron Freedman
using UnityEngine;
using UnityEngine.UI;
namespace Assets.PrototypingKit
{
public class AlphaFadeOut : MonoBehaviour
{
public enum FadeType
{
sprite,
text
}
public FadeType type;
public float speed;
public float startDelay;
private void Start()
{
}
private void Update()
{
if (startDelay > 0)
{
startDelay -= Time.deltaTime;
return;
}
switch (type)
{
case FadeType.sprite:
var sprite = GetComponent<SpriteRenderer>();
sprite.color = Color.Lerp(sprite.color, Color.clear, Time.deltaTime * speed);
break;
case FadeType.text:
var text = GetComponent<Text>();
var c = new Color(text.color.r, text.color.g, text.color.b, 0);
text.color = Color.Lerp(text.color, c, Time.deltaTime * speed);
break;
}
}
}
}