-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFadeManager.cs
More file actions
48 lines (41 loc) · 1.28 KB
/
Copy pathFadeManager.cs
File metadata and controls
48 lines (41 loc) · 1.28 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FadeManager : MonoBehaviour
{
public Image fadeImage;
public float fadeSpeed;
public bool fading;
private void Awake() {
fadeImage.transform.localScale = new Vector2(Screen.width, Screen.height);
StartCoroutine(Fade());
}
public IEnumerator Fade() {
fading = true;
yield return FadeIn();
yield return new WaitForSeconds(0.5f);
yield return FadeOut();
fading = false;
}
public IEnumerator FadeIn() {
while(fading) {
fadeImage.color = Color.Lerp(fadeImage.color, Color.black, fadeSpeed * Time.deltaTime);
if (fadeImage.color.a >= 0.95f) {
fadeImage.color = Color.black;
yield break;
}
yield return null;
}
}
public IEnumerator FadeOut() {
while (fading) {
fadeImage.color = Color.Lerp(fadeImage.color, Color.clear, fadeSpeed * Time.deltaTime);
if (fadeImage.color.a <= 0.05f) {
fadeImage.color = Color.clear;
yield break;
}
yield return null;
}
}
}