質問編集履歴

3

修正

2020/01/16 14:02

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -11,3 +11,349 @@
11
11
  ###実現したいこと
12
12
 
13
13
  PCビルドでも正常にゲームができて欲しい
14
+
15
+
16
+
17
+ ### 該当コード
18
+
19
+ ```unity
20
+
21
+ gamemanagerコード
22
+
23
+ void Start()
24
+
25
+ {
26
+
27
+ //開始時にRedayステート開始
28
+
29
+ Ready();
30
+
31
+ Player = GameObject.FindWithTag("Playercon");
32
+
33
+ playcon = Player.GetComponent<PlayerCotroller>();
34
+
35
+ Time.timeScale = 1;
36
+
37
+ PlayerPrefs.SetInt("NowScore", 0);
38
+
39
+ }
40
+
41
+
42
+
43
+ void LateUpdate()
44
+
45
+ {
46
+
47
+ //ステートごとにイベント監視
48
+
49
+ switch (state)
50
+
51
+ {
52
+
53
+ case State.Ready://タッチしたらゲームスタート
54
+
55
+ if (Input.GetButtonDown("Fire1")||Input.GetKeyDown("space")) GameStart();
56
+
57
+ break;
58
+
59
+ case State.Play://車が破壊されたらゲームオーバー
60
+
61
+ if (playcon.IsDead()) GameOver();
62
+
63
+ break;
64
+
65
+ case State.GameOver:
66
+
67
+ count += Time.deltaTime;
68
+
69
+ if (count >= 1.0f)
70
+
71
+ {
72
+
73
+ Time.timeScale = 0;
74
+
75
+ Title.gameObject.SetActive(true);//タイトルボタン表示
76
+
77
+ StateLabel.gameObject.SetActive(false);
78
+
79
+ scoreLabel.gameObject.SetActive(false);
80
+
81
+ coinLabel.gameObject.SetActive(false);
82
+
83
+ if (Input.GetKeyDown("space"))
84
+
85
+ {
86
+
87
+ //ゲームシーンを読み込み
88
+
89
+ SceneManager.LoadScene("Game");
90
+
91
+ }
92
+
93
+ if (Input.GetKeyDown("right")||Input.GetKeyDown("left"))
94
+
95
+ {
96
+
97
+ //タイトルシーンを読み込み
98
+
99
+ SceneManager.LoadScene("Title");
100
+
101
+ }
102
+
103
+ }
104
+
105
+ break;
106
+
107
+ }
108
+
109
+ }
110
+
111
+
112
+
113
+ // Update is called once per frame
114
+
115
+ void Update()
116
+
117
+ {
118
+
119
+ PlayerPrefs.SetInt("NowScore", score);
120
+
121
+ }
122
+
123
+
124
+
125
+ void Ready()
126
+
127
+ {
128
+
129
+ state = State.Ready;
130
+
131
+ //オブジェクトを無効にする
132
+
133
+ EnemyGenerator.SetActive(false);
134
+
135
+ CoinGenerator.SetActive(false);
136
+
137
+ //ラベル更新
138
+
139
+ scoreLabel.text = "Score : " + 0;
140
+
141
+ StateLabel.gameObject.SetActive(true);
142
+
143
+ StateLabel.text = "READY";
144
+
145
+ coinLabel.text = "Coin : " + 0;
146
+
147
+ }
148
+
149
+ void GameStart()
150
+
151
+ {
152
+
153
+ state = State.Play;
154
+
155
+ //オブジェクトを有効にする
156
+
157
+ EnemyGenerator.SetActive(true);
158
+
159
+ CoinGenerator.SetActive(true);
160
+
161
+ //ラベル更新
162
+
163
+ StateLabel.gameObject.SetActive(false);
164
+
165
+ StateLabel.text = "";
166
+
167
+ }
168
+
169
+ void GameOver()
170
+
171
+ {
172
+
173
+ state = State.GameOver;
174
+
175
+ //ラベル更新
176
+
177
+ StateLabel.gameObject.SetActive(true);
178
+
179
+ //オブジェクトを無効にする
180
+
181
+ EnemyGenerator.SetActive(false);
182
+
183
+ CoinGenerator.SetActive(false);
184
+
185
+ StateLabel.text = "GAMEOVER";
186
+
187
+ //ハイスコアを更新
188
+
189
+ if (PlayerPrefs.GetInt("ScoreHighScore") < score)
190
+
191
+ {
192
+
193
+ PlayerPrefs.SetInt("ScoreHighScore", score);
194
+
195
+ }
196
+
197
+ PlayerPrefs.SetInt("Totalcoin", coin + PlayerPrefs.GetInt("Totalcoin"));
198
+
199
+ endscoreLabel.text = "Score : " + score;
200
+
201
+ endcoinLabel.text = "Coin : " + coin;
202
+
203
+ }
204
+
205
+ ```
206
+
207
+ ```unity
208
+
209
+ playercontrollerコード
210
+
211
+ public bool IsDead()
212
+
213
+ {
214
+
215
+ return isDead;
216
+
217
+ }
218
+
219
+
220
+
221
+ // Start is called before the first frame update
222
+
223
+ void Start()
224
+
225
+ {
226
+
227
+ controller = GetComponent<CharacterController>();//キャラコントローラー取得
228
+
229
+ }
230
+
231
+
232
+
233
+ // Update is called once per frame
234
+
235
+ void Update()
236
+
237
+ {
238
+
239
+ //死んでいたら動かせない
240
+
241
+ if (isDead) return;
242
+
243
+
244
+
245
+ //フリック入力(スマホ用)
246
+
247
+ Flick();
248
+
249
+ //矢印入力(PC用)
250
+
251
+ if (Input.GetKeyDown("right")) MoveToRight();
252
+
253
+ if (Input.GetKeyDown("left")) MoveToLeft();
254
+
255
+
256
+
257
+ //X方向は目的のポジションまでの差分の割合で速度計算
258
+
259
+ float ratioX = (targetLane * LaneWidth - transform.position.x) / LaneWidth;
260
+
261
+ moveDirection.x = ratioX * speedX;
262
+
263
+
264
+
265
+ moveDirection.y -= gravity * Time.deltaTime;//重力加える
266
+
267
+
268
+
269
+ //移動実行
270
+
271
+ Vector3 gloabalDirection = transform.TransformDirection(moveDirection);
272
+
273
+ controller.Move(gloabalDirection * Time.deltaTime);
274
+
275
+ }
276
+
277
+
278
+
279
+ public void ReDead()
280
+
281
+ {
282
+
283
+ //ぶつかったらフラグを立てる
284
+
285
+ isDead = true;
286
+
287
+ }
288
+
289
+
290
+
291
+ ```
292
+
293
+ ```unity
294
+
295
+ playerdeadコード
296
+
297
+ GameObject Dead;
298
+
299
+ public GameObject explosion;
300
+
301
+
302
+
303
+ // Start is called before the first frame update
304
+
305
+ void Start()
306
+
307
+ {
308
+
309
+ //開始時にplayerを見つける
310
+
311
+ Dead = GameObject.FindWithTag("Playercon");
312
+
313
+ }
314
+
315
+
316
+
317
+ // Update is called once per frame
318
+
319
+ void Update()
320
+
321
+ {
322
+
323
+
324
+
325
+ }
326
+
327
+
328
+
329
+ public void OnTriggerEnter(Collider other)
330
+
331
+ {
332
+
333
+ if (other.gameObject.CompareTag("Playercon"))
334
+
335
+ {
336
+
337
+ Dead.SendMessage("ReDead");
338
+
339
+ }
340
+
341
+ Collider thiscol = GetComponent<Collider>();
342
+
343
+ Vector3 hit = thiscol.ClosestPointOnBounds(other.transform.position);
344
+
345
+ if (other.gameObject.CompareTag("Playercon"))
346
+
347
+ {
348
+
349
+ GameObject go = Instantiate(explosion, hit, Quaternion.identity) as GameObject;
350
+
351
+ go.transform.parent = transform;
352
+
353
+ }
354
+
355
+
356
+
357
+ }
358
+
359
+ ```

2

2020/01/16 14:02

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ###現状
2
2
 
3
- 車を避けていくゲームを制作していて完成したのでビルドしてアプリケーション開いてみるとゲームは始めれるのですがゲームオーバーにもならずにスコアも上がらない
3
+ 車を避けていくゲームを制作していて完成したのでビルドしてアプリケーション開いてみるとゲームは始めれるのですが当たり判定はあるがゲームオーバーにもならずにスコアも上がらない
4
4
 
5
5
 
6
6
 

1

2020/01/16 10:19

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  Unityのpcでしてる分にはきちんとできるのですがビルドするとできなくなります
8
8
 
9
+ 後なぜかすぐに(体感いつもの1/20)ビルド終わります
10
+
9
11
  ###実現したいこと
10
12
 
11
13
  PCビルドでも正常にゲームができて欲しい