This repository was archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScreenDimManager.cs
More file actions
56 lines (50 loc) · 1.33 KB
/
Copy pathScreenDimManager.cs
File metadata and controls
56 lines (50 loc) · 1.33 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
using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.UI;
public class ScreenDimManager : MonoBehaviour
{
public Image screenOverlay;
public float fadeSpeed = 1f;
private Color targetColor;
private Color currentColor;
private Color previousColor;
private float fadeAmount;
[UsedImplicitly] public bool isFading;
// Start is called before the first frame update
void Start()
{
currentColor = screenOverlay.color;
targetColor = currentColor;
previousColor = currentColor;
fadeAmount = 0f;
isFading = false;
}
// Update is called once per frame
void Update()
{
if (isFading)
{
fadeAmount += fadeSpeed * Time.deltaTime;
currentColor = Color.Lerp(previousColor, targetColor, fadeAmount);
isFading = fadeAmount < 1f;
screenOverlay.color = currentColor;
}
if (!isFading)
{
currentColor = targetColor;
}
}
public void FadeTo(Color newColor)
{
if (newColor == targetColor)
{
return;
}
targetColor = newColor;
previousColor = currentColor;
fadeAmount = 0f;
isFading = true;
}
}