Tanoda
FadeOut.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using NaughtyAttributes;
4using UnityEngine;
5using UnityEngine.SceneManagement;
6
7public class FadeOut : MonoBehaviour
8{
9 public static FadeOut instance;
10 public bool stillWhite = true;
11 public bool allBlack = false;
12
13 void Awake()
14 {
15 if (!instance)
16 instance = this;
17 if (!SavedUser.instance.isTutorial)
18 {
19 var mat = GetComponent<MeshRenderer>().material;
20 mat.SetColor("_Color", new Color(0, 0, 0, 0));
21 }
22 }
23 [Button]
24 public void FadeOutNow()
25 {
26 StartCoroutine(Fading());
27 }
28
29 public void FadeInNow()
30 {
31 StartCoroutine(Fading(true));
32 }
33
34 [Button]
35 public void WhiteAwayNow()
36 {
37 StartCoroutine(WhiteAway());
38 }
39
40 private IEnumerator Fading(bool IN = false)
41 {
42 var mat = GetComponent<MeshRenderer>().material;
43 for (float i = 0; i < 100; i++)
44 {
45 yield return new WaitForSeconds(0.005f);
46 mat.SetColor("_Color", new Color(0,0,0, IN ? 1 - i/100 : i/100));
47 }
48
49 allBlack = !IN;
50 }
51
52 private IEnumerator WhiteAway()
53 {
54 var mat = GetComponent<MeshRenderer>().material;
55 for (float i = 0; i < 100; i++)
56 {
57 yield return new WaitForSeconds(0.005f);
58 mat.SetColor("_Color", new Color(1,1,1, 1 - i/100));
59 }
60
61 stillWhite = false;
62 }
63}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
UnityEngine.Color Color
Definition: TestScript.cs:32
static FadeOut instance
Definition: FadeOut.cs:9
void FadeInNow()
Definition: FadeOut.cs:29
bool allBlack
Definition: FadeOut.cs:11
bool stillWhite
Definition: FadeOut.cs:10
void WhiteAwayNow()
Definition: FadeOut.cs:35
void FadeOutNow()
Definition: FadeOut.cs:24