質問編集履歴
1
イメージ画像・コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,3 +13,159 @@
|
|
13
13
|
何かいい方法はないでしょうか。
|
14
14
|
|
15
15
|
よろしくお願いいたします。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+

|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
using System.Collections;
|
26
|
+
|
27
|
+
using System.Collections.Generic;
|
28
|
+
|
29
|
+
using UnityEngine;
|
30
|
+
|
31
|
+
using UnityEngine.UI; //パネルのイメージを操作するのに必要
|
32
|
+
|
33
|
+
using UnityEngine.SceneManagement;
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
public class FadeController : MonoBehaviour
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
float fadeSpeed = 0.02f; //透明度が変わるスピードを管理
|
44
|
+
|
45
|
+
float red, green, blue, alfa; //パネルの色、不透明度を管理
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
public bool isFadeOut = false; //フェードアウト処理の開始、完了を管理するフラグ
|
50
|
+
|
51
|
+
public bool isFadeIn = false; //フェードイン処理の開始、完了を管理するフラグ
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
Image fadeImage; //透明度を変更するパネルのイメージ
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
void Start()
|
60
|
+
|
61
|
+
{
|
62
|
+
|
63
|
+
fadeImage = GetComponent<Image>();
|
64
|
+
|
65
|
+
red = fadeImage.color.r;
|
66
|
+
|
67
|
+
green = fadeImage.color.g;
|
68
|
+
|
69
|
+
blue = fadeImage.color.b;
|
70
|
+
|
71
|
+
alfa = fadeImage.color.a;
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
void Update()
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
if (isFadeIn)
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
StartFadeIn();
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
if (isFadeOut)
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
StartFadeOut();
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
void StartFadeIn()
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
alfa -= fadeSpeed; //a)不透明度を徐々に下げる
|
108
|
+
|
109
|
+
SetAlpha(); //b)変更した不透明度パネルに反映する
|
110
|
+
|
111
|
+
if (alfa <= 0)
|
112
|
+
|
113
|
+
{ //c)完全に透明になったら処理を抜ける
|
114
|
+
|
115
|
+
isFadeIn = false;
|
116
|
+
|
117
|
+
fadeImage.enabled = false; //d)パネルの表示をオフにする
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
void StartFadeOut()
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
fadeImage.enabled = true; // a)パネルの表示をオンにする
|
130
|
+
|
131
|
+
alfa += fadeSpeed; // b)不透明度を徐々にあげる
|
132
|
+
|
133
|
+
SetAlpha(); // c)変更した透明度をパネルに反映する
|
134
|
+
|
135
|
+
if (alfa >= 1)
|
136
|
+
|
137
|
+
{ // d)完全に不透明になったら処理を抜ける
|
138
|
+
|
139
|
+
isFadeOut = false;
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
void SetAlpha()
|
148
|
+
|
149
|
+
{
|
150
|
+
|
151
|
+
fadeImage.color = new Color(red, green, blue, alfa);
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
// スタートボタンを押したら実行する
|
158
|
+
|
159
|
+
public void GameStart()
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
SceneManager.LoadScene("Opening");
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
```
|