-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFader.cs
More file actions
61 lines (50 loc) · 1.37 KB
/
Fader.cs
File metadata and controls
61 lines (50 loc) · 1.37 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
using System;
using UnityEngine;
namespace Agricosmic.Utilities
{
public class Fader : MonoBehaviour
{
[SerializeField] private SpriteRenderer _renderer;
private bool _inTempMode = false;
private float _time;
private float _maxTime;
private Color _color;
private void Start()
{
if (_renderer == null) _renderer = GetComponent<SpriteRenderer>();
_renderer.color = new(1, 1, 1, 0);
}
private void Update()
{
if (_inTempMode)
{
if (_time > 0f)
{
_time -= Time.deltaTime;
_renderer.color = new(_color.r, _color.g, _color.b, _time / _maxTime);
_renderer.enabled = true;
}
else
{
_renderer.enabled = false;
}
}
else
{
_renderer.color = _color;
}
}
public void SetAlphaAndColor(Color color)
{
_color = color;
}
public void FadeOutForTime(Color color, float time)
{
_inTempMode = true;
_renderer.color = color;
_color = color;
_maxTime = time;
_time = time;
}
}
}