質問編集履歴

2

コードの訂正

2018/09/15 03:59

投稿

4423
4423

スコア16

test CHANGED
File without changes
test CHANGED
@@ -248,7 +248,7 @@
248
248
 
249
249
 
250
250
 
251
- m_HPimage.fillAmount -= 0.1f / m_PlayerScript.HP;
251
+ m_HPimage.fillAmount -= 1.0f / m_PlayerScript.HP;
252
252
 
253
253
 
254
254
 

1

スクリプトの追加

2018/09/15 03:59

投稿

4423
4423

スコア16

test CHANGED
File without changes
test CHANGED
@@ -102,6 +102,8 @@
102
102
 
103
103
  }
104
104
 
105
+
106
+
105
107
  ```
106
108
 
107
109
  ```ここに言語を入力
@@ -174,6 +176,98 @@
174
176
 
175
177
  ```
176
178
 
179
+ ```ここに言語を入力
180
+
181
+
182
+
183
+ ***追加分 HPイメージスクリプト****
184
+
185
+
186
+
187
+ using System.Collections;
188
+
189
+ using System.Collections.Generic;
190
+
191
+ using UnityEngine;
192
+
193
+ using UnityEngine.UI;
194
+
195
+
196
+
197
+ public class HpGauge : MonoBehaviour
198
+
199
+ {
200
+
201
+ [SerializeField]
202
+
203
+ private GameObject m_Player;
204
+
205
+ private PlayerMove m_PlayerScript;
206
+
207
+ private Image m_HPimage;
208
+
209
+
210
+
211
+ private void Start()
212
+
213
+ {
214
+
215
+ m_PlayerScript = m_Player.GetComponent<PlayerMove>();
216
+
217
+ m_HPimage = gameObject.GetComponent<Image>();
218
+
219
+ m_HPimage.fillAmount = 1.0f;
220
+
221
+ }
222
+
223
+
224
+
225
+ // Update is called once per frame
226
+
227
+ void Update()
228
+
229
+ {
230
+
231
+ if (m_PlayerScript.HP <= 0)
232
+
233
+ {
234
+
235
+ m_HPimage.fillAmount = 0;
236
+
237
+ }
238
+
239
+
240
+
241
+
242
+
243
+ while (m_PlayerScript.HP > 0)
244
+
245
+ {
246
+
247
+
248
+
249
+
250
+
251
+ m_HPimage.fillAmount -= 0.1f / m_PlayerScript.HP;
252
+
253
+
254
+
255
+ if (m_PlayerScript.HP <= 10)
256
+
257
+ { // 10以下になったら点滅する
258
+
259
+ Flashing(m_HPimage.color);
260
+
261
+ }
262
+
263
+ }
264
+
265
+ }
266
+
267
+ ```
268
+
269
+
270
+
177
271
  ![イメージ説明](312ddaa74054997be124709d87a453c7.png)
178
272
 
179
273
  ![イメージ説明](f110e910f8cfd4e175c0f3d3c2d42c47.png)