teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

コードの追加

2021/09/03 12:59

投稿

BounceTime
BounceTime

スコア2

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,6 @@
1
+ ```ここに言語を入力
2
+ コード
1
- ### 前提・実現したいこと
3
+ ```### 前提・実現したいこと
2
4
 
3
5
  とても初歩的な質問で失礼します
4
6
  EnemyのHPが0になったことを契機にTrueにして表示したPanelを
@@ -12,7 +14,7 @@
12
14
 
13
15
  ### 該当のソースコード
14
16
 
15
- ```
17
+ ``````
16
18
  using System.Collections;
17
19
  using System.Collections.Generic;
18
20
  using UnityEngine;
@@ -103,7 +105,8 @@
103
105
  enemy.Damage(Ratp);
104
106
  IsPlayerTurn = false;
105
107
  }
108
+ }
106
- }```
109
+ ```
107
110
  ### 試したこと
108
111
 
109
112
  関数をInvoke,StartCoroutineに置き換えて実行してみたがどうしても非表示の処理だけが行われません。

2

コードの追加

2021/09/03 12:59

投稿

BounceTime
BounceTime

スコア2

title CHANGED
File without changes
body CHANGED
@@ -12,24 +12,98 @@
12
12
 
13
13
  ### 該当のソースコード
14
14
 
15
+ ```
16
+ using System.Collections;
17
+ using System.Collections.Generic;
15
- C#,Unity
18
+ using UnityEngine;
19
+ using UnityEngine.UI;
16
20
 
21
+ public class MainSystem : MonoBehaviour
22
+ {
23
+ public int Ratp;
24
+ public Player player;
25
+ public Enemy enemy;
26
+ public GameObject ResultPanel;
27
+ public GameObject NextStagePanel;
28
+ //PlayerTurnのTF
29
+ bool IsPlayerTurn;
17
- //NextStage画面を出す処理
30
+ //GameOverのTF
31
+ bool IsGameOver;
32
+ //次enemy出現タイムのTF
33
+
34
+ float second = 0f;
35
+
18
- void ViewNextStage()
36
+ void Start()
19
37
  {
38
+ //PlayerTurnをT、GameOverをF、GameOver画面を隠す
39
+ IsPlayerTurn = true;
40
+ IsGameOver = false;
41
+ ResultPanel.SetActive(false);
20
- NextStagePanel.SetActive(true);
42
+ NextStagePanel.SetActive(false);
43
+ }
44
+
45
+ //GameOver画面を出す処理
46
+ void ViewResult()
47
+ {
21
- Debug.Log("Trueに変更");
48
+ ResultPanel.SetActive(true);
49
+ }
50
+ //NextStage画面を出す処理
51
+
52
+ void Update()
53
+ {
22
- StepTime += Time.deltaTime;
54
+ //Playerのターン終了後の処理
23
- if (StepTime >= 3.0f)!
55
+ if (!IsPlayerTurn)
24
56
  {
57
+ //enemyのターン、playerターンの1秒後に開始
25
- NextStagePanel.SetActive(false);
58
+ second += Time.deltaTime;
59
+ if (second >= 1f)
60
+ {
61
+ //playerはenemyの攻撃力分のダメージを受け、enemyターン終了
62
+ player.Damage(enemy.atp);
26
- IsBreakTime = false;
63
+ IsPlayerTurn = true;
27
- Debug.Log("falseに変更");
64
+ second = 0f;
65
+ }
28
66
  }
67
+
68
+ if(enemy.hp <= 0)
69
+ {
70
+ Destroy(this.gameObject);
71
+ Debug.Log("Trueに変更");
72
+ StartCoroutine(ShowImageSecond(NextStagePanel, 2f));
73
+ }
74
+ //playerが負けた際の処理
75
+ if(player.hp <= 0)
76
+ {
77
+ IsGameOver = true;
78
+ }
79
+ //GameOverになった時の処理
80
+ if(IsGameOver)
81
+ {
82
+ ViewResult();
83
+ return;
84
+ }
85
+
29
86
  }
30
- ![イメージ説明](3f31a922c68e18c99fe5ba4dcd6f83ca.png)
31
- ![イメージ説明](fb34c2fccc60cd2ee281522b5b700a40.png)
32
87
 
88
+ IEnumerator ShowImageSecond(GameObject targetObj,float sec)
89
+ {
90
+ targetObj.SetActive(true);
91
+
92
+ yield return new WaitForSeconds(sec);
93
+
94
+ targetObj.SetActive(false);
95
+ }
96
+
97
+ //攻撃ボタンを押した時の処理
98
+ public void PushAttackButton()
99
+ {
100
+ //player攻撃力の抽選、Ratpに代入、攻撃、playerターンの終了
101
+ Ratp = Random.Range(1, 1000);
102
+ Debug.Log(Ratp);
103
+ enemy.Damage(Ratp);
104
+ IsPlayerTurn = false;
105
+ }
106
+ }```
33
107
  ### 試したこと
34
108
 
35
109
  関数をInvoke,StartCoroutineに置き換えて実行してみたがどうしても非表示の処理だけが行われません。

1

タグの追加

2021/09/03 12:21

投稿

BounceTime
BounceTime

スコア2

title CHANGED
File without changes
body CHANGED
File without changes