回答編集履歴

5

文法の修正

2018/07/02 10:39

投稿

退会済みユーザー
test CHANGED
@@ -154,8 +154,6 @@
154
154
 
155
155
  rb2D = GetComponent<Rigidbody2D>();
156
156
 
157
- pObject.gameObject.SetActive(false);
158
-
159
157
  }
160
158
 
161
159
 
@@ -186,16 +184,12 @@
186
184
 
187
185
  GameOverGUI.SendMessage("Lose");
188
186
 
189
- pObject.gameObject.SetActive(true);
190
-
191
187
 
192
188
 
193
189
  yield return new WaitForSeconds(1f);
194
190
 
195
191
 
196
192
 
197
- pObject.gameObject.SetActive(false);
198
-
199
193
  gameObject.SetActive (false);
200
194
 
201
195
  while(!Input.GetMouseButtonDown(0)) { yield return 0; }

4

文法の修正

2018/07/02 10:39

投稿

退会済みユーザー
test CHANGED
@@ -132,12 +132,6 @@
132
132
 
133
133
  public class CubeController : MonoBehaviour {
134
134
 
135
- [SerializeField]
136
-
137
- ParticleSystem pObject;
138
-
139
- private Explodable _explodable;
140
-
141
135
  public AudioClip Point;
142
136
 
143
137
  private AudioSource audioSource1;
@@ -160,8 +154,6 @@
160
154
 
161
155
  rb2D = GetComponent<Rigidbody2D>();
162
156
 
163
- _explodable = GetComponent<Explodable>();
164
-
165
157
  pObject.gameObject.SetActive(false);
166
158
 
167
159
  }

3

文法の修正

2018/07/02 10:36

投稿

退会済みユーザー
test CHANGED
@@ -176,18 +176,6 @@
176
176
 
177
177
  Jump ();
178
178
 
179
- }
180
-
181
- if (gameover == true) {
182
-
183
- // _explodable.explode();
184
-
185
- // ExplosionForce ef = GameObject.FindObjectOfType<ExplosionForce>();
186
-
187
- // ef.doExplosion(transform.position);
188
-
189
- }
190
-
191
179
  }
192
180
 
193
181
 

2

文法の修正

2018/07/02 10:32

投稿

退会済みユーザー
test CHANGED
@@ -115,3 +115,137 @@
115
115
  }
116
116
 
117
117
  ```
118
+
119
+ から
120
+
121
+ ```c#
122
+
123
+ using System.Collections;
124
+
125
+ using System.Collections.Generic;
126
+
127
+ using UnityEngine;
128
+
129
+ using UnityEngine.SceneManagement;
130
+
131
+
132
+
133
+ public class CubeController : MonoBehaviour {
134
+
135
+ [SerializeField]
136
+
137
+ ParticleSystem pObject;
138
+
139
+ private Explodable _explodable;
140
+
141
+ public AudioClip Point;
142
+
143
+ private AudioSource audioSource1;
144
+
145
+ private Rigidbody2D rb2D;
146
+
147
+ private float jumpForce = 4.0f;
148
+
149
+ public GameObject Score;
150
+
151
+ public GameObject GameOverGUI;
152
+
153
+ private bool gameover = false;
154
+
155
+
156
+
157
+ private void Start () {
158
+
159
+ gameObject.SetActive (true);
160
+
161
+ rb2D = GetComponent<Rigidbody2D>();
162
+
163
+ _explodable = GetComponent<Explodable>();
164
+
165
+ pObject.gameObject.SetActive(false);
166
+
167
+ }
168
+
169
+
170
+
171
+ void Update () {
172
+
173
+ //gameoverフラグがtrueになった時、ジャンプできないようにする
174
+
175
+ if (Input.GetMouseButtonDown (0) && !gameover) {
176
+
177
+ Jump ();
178
+
179
+ }
180
+
181
+ if (gameover == true) {
182
+
183
+ // _explodable.explode();
184
+
185
+ // ExplosionForce ef = GameObject.FindObjectOfType<ExplosionForce>();
186
+
187
+ // ef.doExplosion(transform.position);
188
+
189
+ }
190
+
191
+ }
192
+
193
+
194
+
195
+ void Jump(){
196
+
197
+ rb2D.velocity = new Vector2(rb2D.velocity.x, jumpForce);
198
+
199
+ }
200
+
201
+
202
+
203
+ IEnumerator OnCollisionEnter2D (Collision2D collision) {
204
+
205
+ gameover = true;
206
+
207
+ GameOverGUI.SendMessage("Lose");
208
+
209
+ pObject.gameObject.SetActive(true);
210
+
211
+
212
+
213
+ yield return new WaitForSeconds(1f);
214
+
215
+
216
+
217
+ pObject.gameObject.SetActive(false);
218
+
219
+ gameObject.SetActive (false);
220
+
221
+ while(!Input.GetMouseButtonDown(0)) { yield return 0; }
222
+
223
+ Application.LoadLevel("TitleScene");
224
+
225
+ }
226
+
227
+
228
+
229
+ void OnTriggerEnter2D (Collider2D col){
230
+
231
+ audioSource1 = gameObject.GetComponent<AudioSource> ();
232
+
233
+ audioSource1.clip = Point;
234
+
235
+ audioSource1.Play ();
236
+
237
+ //Score(GUIText)のScoreUpメソッドを呼び出す
238
+
239
+ Score.SendMessage ("ScoreUp", 1);
240
+
241
+ //何度も加点されないように削除しておく
242
+
243
+ Destroy (col.gameObject);
244
+
245
+ }
246
+
247
+ }
248
+
249
+ ```
250
+
251
+ に変更したところ直りました。

1

文法の修正

2018/07/02 10:30

投稿

退会済みユーザー
test CHANGED
@@ -1 +1,117 @@
1
+ ```c#
2
+
3
+ using System.Collections;
4
+
5
+ using System.Collections.Generic;
6
+
1
- 少しコードをいじってみたら直りました。
7
+ using UnityEngine;
8
+
9
+
10
+
11
+ public class CubeController : MonoBehaviour {
12
+
13
+ public AudioClip Point;
14
+
15
+ private AudioSource audioSource1;
16
+
17
+ private Rigidbody2D rb2D;
18
+
19
+ private float jumpForce = 4.0f;
20
+
21
+ public GameObject Score;
22
+
23
+ public GameObject GameOverGUI;
24
+
25
+ private bool gameover = false;
26
+
27
+
28
+
29
+ // Use this for initialization
30
+
31
+ private void Start () {
32
+
33
+ rb2D = GetComponent<Rigidbody2D>();
34
+
35
+ }
36
+
37
+
38
+
39
+ void Update () {
40
+
41
+ //gameoverフラグがtrueになった時、ジャンプできないようにする
42
+
43
+ if(Input.GetMouseButtonDown(0) && !gameover){
44
+
45
+ Jump();
46
+
47
+ }
48
+
49
+ if(gameover == true){
50
+
51
+ //GAME OVERのGUIを表示する
52
+
53
+ GameOverGUI.SendMessage("Lose");
54
+
55
+ }
56
+
57
+ }
58
+
59
+
60
+
61
+ void Jump(){
62
+
63
+ rb2D.velocity = new Vector2(rb2D.velocity.x, jumpForce);
64
+
65
+ }
66
+
67
+
68
+
69
+ private void OnCollisionEnter2D (Collision2D collision) {
70
+
71
+ StartCoroutine(GameOver());
72
+
73
+ }
74
+
75
+
76
+
77
+ void OnTriggerEnter2D (Collider2D col){
78
+
79
+ audioSource1 = gameObject.GetComponent<AudioSource> ();
80
+
81
+ audioSource1.clip = Point;
82
+
83
+ audioSource1.Play ();
84
+
85
+ //Score(GUIText)のScoreUpメソッドを呼び出す
86
+
87
+ Score.SendMessage ("ScoreUp", 1);
88
+
89
+ //何度も加点されないように削除しておく
90
+
91
+ Destroy (col.gameObject);
92
+
93
+ }
94
+
95
+
96
+
97
+ IEnumerator GameOver() {
98
+
99
+ // ゲームオーバーのフラグをtrueにする
100
+
101
+ gameover = true;
102
+
103
+ // マウス連打してたらスコアを見る暇もなくタイトルへ戻ってしまう対策、1秒待機
104
+
105
+ yield return new WaitForSeconds(1f);
106
+
107
+ // マウスクリックしたらゲームの最初に戻る
108
+
109
+ while(!Input.GetMouseButtonDown(0)) { yield return 0; }
110
+
111
+ Application.LoadLevel("TitleScene");
112
+
113
+ }
114
+
115
+ }
116
+
117
+ ```