質問編集履歴

2

誤字

2018/09/17 13:25

投稿

syah
syah

スコア16

test CHANGED
File without changes
test CHANGED
@@ -306,8 +306,6 @@
306
306
 
307
307
 
308
308
 
309
- 回答ありがとうございます。
310
-
311
309
  言葉足らずで申し訳ないです。
312
310
 
313
311
  早速public bool shootbuttonと宣言し、Inspectorで見たところ、shootbuttonの値がボタンを押してる間はtrueになり、離したときにfalseになっていたことを確認できました。

1

追記と画像の追加

2018/09/17 13:24

投稿

syah
syah

スコア16

test CHANGED
File without changes
test CHANGED
@@ -297,3 +297,109 @@
297
297
  なおUpdateメソッド内ではshootbuttonをtrueに代入できました。ボタンは反応しているはずだと思いましたが、なぜshootbuttonに代入されないのかわかりません。
298
298
 
299
299
  Unityのバージョンは2017.4.10f1 Personal(64bit)です。
300
+
301
+
302
+
303
+ -------------------------------------------------------------------
304
+
305
+ **追記**
306
+
307
+
308
+
309
+ 回答ありがとうございます。
310
+
311
+ 言葉足らずで申し訳ないです。
312
+
313
+ 早速public bool shootbuttonと宣言し、Inspectorで見たところ、shootbuttonの値がボタンを押してる間はtrueになり、離したときにfalseになっていたことを確認できました。
314
+
315
+
316
+
317
+ 「shootbuttonがtrueにならないことをどうやって確認したのか?」についてですが、
318
+
319
+ 私は最初にUpdateメソッド内で
320
+
321
+ Debug.Log(shootbutton);
322
+
323
+ とした時にコンソールではTrueは表示されず、Falseしか表示されないことを確認しました。
324
+
325
+ ※画像ではわかりやすくするために
326
+
327
+ Debug.Log(("shootbuttonは")+shootbutton);
328
+
329
+ としました。
330
+
331
+ ```c#
332
+
333
+ void Update ()
334
+
335
+ {
336
+
337
+ Debug.Log(("shootbuttonは")+shootbutton);
338
+
339
+ if (shootbutton)
340
+
341
+ {
342
+
343
+ Debug.Log("Shoot!");
344
+
345
+ }
346
+
347
+ // 右・左
348
+
349
+ float x = CrossPlatformInputManager.GetAxisRaw("Horizontal");
350
+
351
+
352
+
353
+ // 上・下
354
+
355
+ float y = CrossPlatformInputManager.GetAxisRaw("Vertical");
356
+
357
+
358
+
359
+ // 移動する向きを求める
360
+
361
+ Vector2 direction = new Vector2(x, y).normalized;
362
+
363
+
364
+
365
+ // 移動の制限
366
+
367
+ Move (direction);
368
+
369
+
370
+
371
+ if (Input.GetKey(KeyCode.Z) || shootbutton)
372
+
373
+ {
374
+
375
+ timeCount1++;
376
+
377
+ if (timeCount1 > spaceship.shotDelay * 10)
378
+
379
+ {
380
+
381
+ timeCount1 = 0;
382
+
383
+ StartCoroutine("GUN");
384
+
385
+ }
386
+
387
+ }
388
+
389
+ else
390
+
391
+ {
392
+
393
+ timeCount1 = spaceship.shotDelay * 10;
394
+
395
+ }
396
+
397
+
398
+
399
+ }
400
+
401
+ ```
402
+
403
+ ![falseしか](f0ba35578797e779af528ab1242f8e27.png)
404
+
405
+ Updateメソッド内ではshootbuttonの値の変化は反映されないのでしょうか。