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
62
63
64
65
66
67
68
69
70
71
|
using UnityEngine; using System.Collections; public class SceneFadeInOut
: MonoBehaviour { public float fadeSpeed
= 1.5f; private bool sceneStarting
= true ; private bool sceneEnding
= false ; void Awake() { guiTexture.pixelInset
= new Rect(0f,
0f, Screen.width, Screen.height); } void Update() { if (sceneStarting) { StartScene(); } if (sceneEnding) { EndScene(); } } void FadeToClear() { guiTexture.color
= Color.Lerp(guiTexture.color, Color.clear, fadeSpeed * Time.deltaTime); } void FadeToBlack() { guiTexture.color
= Color.Lerp (guiTexture.color, Color.black, fadeSpeed * Time.deltaTime); } void StartScene() { FadeToClear(); if (guiTexture.color.a
< 0.05f) { guiTexture.color
= Color.clear; guiTexture.enabled
= false ; sceneStarting
= false ; } } public void EndScene() { guiTexture.enabled
= true ; FadeToBlack(); if (guiTexture.color.a
>= 0.95f) { sceneEnding
= false ; Application.LoadLevel(1); } } void OnGUI() { if (!sceneStarting
&& GUI.Button ( new Rect(0,0,100,100), "NewLevel" )) { sceneEnding
= true ; } } } |
Unity 切换游戏场景时屏幕淡入淡出效果 第二版
最新推荐文章于 2025-06-13 23:52:22 发布