質問編集履歴
8
画像の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,10 @@
|
|
12
12
|
|
13
13
|
最終地点は、ゲーム内通貨を消費してアイテムを購入するシステムの構築です。
|
14
14
|
|
15
|
+
まさに以下の画像のようなイメージです。
|
16
|
+
|
17
|
+

|
18
|
+
|
15
19
|
|
16
20
|
|
17
21
|
### 現状
|
@@ -52,13 +56,19 @@
|
|
52
56
|
|
53
57
|
|
54
58
|
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
55
65
|
```C#
|
56
66
|
|
57
67
|
|
58
68
|
|
59
69
|
using System.Collections;
|
60
70
|
|
61
|
-
using Sy
|
71
|
+
using Syollections.Generic;
|
62
72
|
|
63
73
|
using UnityEngine;
|
64
74
|
|
7
コードブロックの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,436 +52,432 @@
|
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
+
```C#
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
using System.Collections;
|
60
|
+
|
61
|
+
using System.Collections.Generic;
|
62
|
+
|
63
|
+
using UnityEngine;
|
64
|
+
|
65
|
+
using UnityEngine.UI;
|
66
|
+
|
67
|
+
using System;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
public class GameManager : MonoBehaviour {
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
//定数定義
|
76
|
+
|
77
|
+
private const int MAX_ORB = 5000; //オーブ最大数
|
78
|
+
|
79
|
+
private const int RESPAWN_TIME = 15; //オーブが発生する秒数
|
80
|
+
|
81
|
+
private const int MAX_LEVEL = 5; //最大キーパーレベル
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
//データセーブ用キー
|
86
|
+
|
87
|
+
private const string KEY_SCORE = "SCORE"; //スコア
|
88
|
+
|
89
|
+
private const string KEY_LEVEL = "LEVEL"; //レベル
|
90
|
+
|
91
|
+
private const string KEY_ORB = "ORB"; //オーブ数
|
92
|
+
|
93
|
+
private const string KEY_TIME = "TIME"; //時間
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
//オブジェクト参照
|
98
|
+
|
99
|
+
public GameObject orbPrefab; //オーブプレハブ
|
100
|
+
|
101
|
+
public GameObject trophyPrefab; //トロフィープレハブ
|
102
|
+
|
103
|
+
public GameObject canvasGame; //ゲームキャンバス
|
104
|
+
|
105
|
+
public GameObject textScore; //スコアテキスト
|
106
|
+
|
107
|
+
public GameObject imageKeeper; //キーパー
|
108
|
+
|
109
|
+
public float clickrate = 0.5f;
|
110
|
+
|
111
|
+
public GameObject ball;
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
//メンバ変数
|
116
|
+
|
117
|
+
private int score = 0; //現在のスコア
|
118
|
+
|
119
|
+
private int nextScore = 400; //レベルアップまでに必要なスコア
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
private int currentOrb = 0; //現在のオーブ数
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
private int keeperLevel = 0; //キーパーのレベル
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
private DateTime lastDateTime; //前回オーブを生成した瞬間
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
private int[] nextScoreTable = new int[] { 100,200,300,400,500 }; //レベルアップ値
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
private int numOfOrb; //まとめて生成するオーブの数
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
// Use this for initialization
|
144
|
+
|
145
|
+
void Start () {
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
//データ削除メソッド
|
150
|
+
|
151
|
+
//PlayerPrefs.DeleteAll();
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
//初期設定
|
156
|
+
|
157
|
+
score = PlayerPrefs.GetInt(KEY_SCORE, 0);
|
158
|
+
|
159
|
+
keeperLevel = PlayerPrefs.GetInt(KEY_LEVEL, 0);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
nextScore = nextScoreTable[keeperLevel];
|
164
|
+
|
165
|
+
imageKeeper.GetComponent<KeeperManager>().SetKeeperPicture(keeperLevel);
|
166
|
+
|
167
|
+
imageKeeper.GetComponent<KeeperManager>().SetKeeperScale(score, nextScore);
|
168
|
+
|
169
|
+
|
170
|
+
|
55
|
-
|
171
|
+
RefreshScoreText();
|
172
|
+
|
173
|
+
|
174
|
+
|
56
|
-
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
57
|
-
|
179
|
+
// Update is called once per frame
|
180
|
+
|
181
|
+
void Update () {
|
182
|
+
|
183
|
+
//まとめて生成するオーブがあれば生成
|
184
|
+
|
185
|
+
while (numOfOrb > 0)
|
186
|
+
|
187
|
+
{
|
188
|
+
|
189
|
+
Invoke("CreateNewOrb",0.1f*numOfOrb);
|
190
|
+
|
191
|
+
numOfOrb--;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
//バックグラウンドへの移行時と復帰時(アプリ起動時も含む)に呼び出される
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
private void OnApplicationPause(bool pauseStatus)
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
if (pauseStatus)
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
//アプリがバックグラウンドへ移行
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
else
|
216
|
+
|
217
|
+
{
|
218
|
+
|
219
|
+
//バックグラウンドから復帰
|
220
|
+
|
221
|
+
//時間の復元
|
222
|
+
|
223
|
+
string time = PlayerPrefs.GetString(KEY_TIME, "");
|
224
|
+
|
225
|
+
if (time == "")
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
lastDateTime = DateTime.UtcNow;
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
else
|
234
|
+
|
235
|
+
{
|
236
|
+
|
237
|
+
long temp = Convert.ToInt64(time);
|
238
|
+
|
239
|
+
lastDateTime = DateTime.FromBinary(temp);
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
numOfOrb = 0;
|
246
|
+
|
247
|
+
//時間によるオーブ自動生成
|
248
|
+
|
249
|
+
TimeSpan timeSpan = DateTime.UtcNow - lastDateTime;
|
250
|
+
|
251
|
+
if (timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME))
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
while (timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME))
|
256
|
+
|
257
|
+
{
|
258
|
+
|
259
|
+
if (numOfOrb < MAX_ORB)
|
260
|
+
|
261
|
+
{
|
262
|
+
|
263
|
+
numOfOrb++;
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
timeSpan -= TimeSpan.FromSeconds(RESPAWN_TIME);
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
//新しいオーブの生成
|
280
|
+
|
281
|
+
public void CreateNewOrb()
|
282
|
+
|
283
|
+
{
|
284
|
+
|
285
|
+
lastDateTime = DateTime.UtcNow;
|
286
|
+
|
287
|
+
if (currentOrb >= MAX_ORB)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
return;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
CreateOrb();
|
296
|
+
|
297
|
+
currentOrb++;
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
SaveGameData();
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
//オーブ生成
|
308
|
+
|
309
|
+
public void CreateOrb()
|
310
|
+
|
311
|
+
{
|
312
|
+
|
313
|
+
GameObject orb = (GameObject)Instantiate(orbPrefab);
|
314
|
+
|
315
|
+
orb.transform.SetParent(canvasGame.transform, false);
|
316
|
+
|
317
|
+
orb.transform.localPosition = new Vector3(
|
318
|
+
|
319
|
+
UnityEngine.Random.Range (-100.0f, 100.0f),
|
320
|
+
|
321
|
+
UnityEngine.Random.Range (-300.0f, -450.0f),
|
322
|
+
|
323
|
+
0f);
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
orb.GetComponent<OrbManager>().Flyorb();
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
//ボールアニメーション
|
332
|
+
|
333
|
+
StartCoroutine("ClickAnim");//"ClickAnim"のコルーチンを呼ぶ.
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
//オーブ入手
|
346
|
+
|
347
|
+
public void GetOrb()
|
348
|
+
|
349
|
+
{
|
350
|
+
|
351
|
+
score += 1;
|
352
|
+
|
353
|
+
//キーパー画像切り替えメソッド挿入予定
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
//レベルアップ値を超えないように制限
|
358
|
+
|
359
|
+
if (score > nextScore)
|
360
|
+
|
361
|
+
{
|
362
|
+
|
363
|
+
score = nextScore;
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
KeeperLevelUp();
|
370
|
+
|
371
|
+
RefreshScoreText();
|
372
|
+
|
373
|
+
imageKeeper.GetComponent<KeeperManager>().SetKeeperScale(score, nextScore);
|
374
|
+
|
375
|
+
SaveGameData();
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
//スコアテキスト更新
|
388
|
+
|
389
|
+
void RefreshScoreText()
|
390
|
+
|
391
|
+
{
|
392
|
+
|
393
|
+
textScore.GetComponent<Text>().text =
|
394
|
+
|
395
|
+
score + "GOAL";
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
//キーパーのレベル管理
|
402
|
+
|
403
|
+
void KeeperLevelUp()
|
404
|
+
|
405
|
+
{
|
406
|
+
|
407
|
+
if (score >= nextScore)
|
408
|
+
|
409
|
+
{
|
410
|
+
|
411
|
+
if (keeperLevel < MAX_LEVEL)
|
412
|
+
|
413
|
+
{
|
414
|
+
|
415
|
+
keeperLevel++;
|
416
|
+
|
417
|
+
score = 0;
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
KeeperLevelUpEffect();
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
nextScore = nextScoreTable[keeperLevel];
|
426
|
+
|
427
|
+
imageKeeper.GetComponent<KeeperManager>().SetKeeperPicture(keeperLevel);
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
}
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
//レベルアップ時の演出
|
438
|
+
|
439
|
+
void KeeperLevelUpEffect()
|
440
|
+
|
441
|
+
{
|
442
|
+
|
443
|
+
GameObject trophy = (GameObject)Instantiate(trophyPrefab);
|
444
|
+
|
445
|
+
trophy.transform.SetParent(canvasGame.transform, false);
|
446
|
+
|
447
|
+
trophy.transform.SetSiblingIndex(5);
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
Destroy(trophy, 0.5f);
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
//ゲームデータをセーブ
|
458
|
+
|
459
|
+
void SaveGameData()
|
460
|
+
|
461
|
+
{
|
462
|
+
|
463
|
+
PlayerPrefs.SetInt(KEY_SCORE, score);
|
464
|
+
|
465
|
+
PlayerPrefs.SetInt(KEY_LEVEL,keeperLevel);
|
466
|
+
|
467
|
+
PlayerPrefs.SetInt(KEY_ORB,currentOrb);
|
468
|
+
|
469
|
+
PlayerPrefs.SetString(KEY_TIME,lastDateTime.ToBinary().ToString());
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
PlayerPrefs.Save();
|
476
|
+
|
477
|
+
}
|
58
478
|
|
59
479
|
```
|
60
480
|
|
61
|
-
using System.Collections;
|
62
|
-
|
63
|
-
using System.Collections.Generic;
|
64
|
-
|
65
|
-
using UnityEngine;
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
using UnityEngine.UI;
|
70
|
-
|
71
|
-
using System;
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
public class GameManager : MonoBehaviour {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
//定数定義
|
80
|
-
|
81
|
-
private const int MAX_ORB = 5000; //オーブ最大数
|
82
|
-
|
83
|
-
private const int RESPAWN_TIME = 15; //オーブが発生する秒数
|
84
|
-
|
85
|
-
private const int MAX_LEVEL = 5; //最大キーパーレベル
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
//データセーブ用キー
|
90
|
-
|
91
|
-
private const string KEY_SCORE = "SCORE"; //スコア
|
92
|
-
|
93
|
-
private const string KEY_LEVEL = "LEVEL"; //レベル
|
94
|
-
|
95
|
-
private const string KEY_ORB = "ORB"; //オーブ数
|
96
|
-
|
97
|
-
private const string KEY_TIME = "TIME"; //時間
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
//オブジェクト参照
|
102
|
-
|
103
|
-
public GameObject orbPrefab; //オーブプレハブ
|
104
|
-
|
105
|
-
public GameObject trophyPrefab; //トロフィープレハブ
|
106
|
-
|
107
|
-
public GameObject canvasGame; //ゲームキャンバス
|
108
|
-
|
109
|
-
public GameObject textScore; //スコアテキスト
|
110
|
-
|
111
|
-
public GameObject imageKeeper; //キーパー
|
112
|
-
|
113
|
-
public float clickrate = 0.5f;
|
114
|
-
|
115
|
-
public GameObject ball;
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
//メンバ変数
|
120
|
-
|
121
|
-
private int score = 0; //現在のスコア
|
122
|
-
|
123
|
-
private int nextScore = 400; //レベルアップまでに必要なスコア
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
private int currentOrb = 0; //現在のオーブ数
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
private int keeperLevel = 0; //キーパーのレベル
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
private DateTime lastDateTime; //前回オーブを生成した瞬間
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
private int[] nextScoreTable = new int[] { 100,200,300,400,500 }; //レベルアップ値
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
private int numOfOrb; //まとめて生成するオーブの数
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
// Use this for initialization
|
148
|
-
|
149
|
-
void Start () {
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
//データ削除メソッド
|
154
|
-
|
155
|
-
//PlayerPrefs.DeleteAll();
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
//初期設定
|
160
|
-
|
161
|
-
score = PlayerPrefs.GetInt(KEY_SCORE, 0);
|
162
|
-
|
163
|
-
keeperLevel = PlayerPrefs.GetInt(KEY_LEVEL, 0);
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
nextScore = nextScoreTable[keeperLevel];
|
168
|
-
|
169
|
-
imageKeeper.GetComponent<KeeperManager>().SetKeeperPicture(keeperLevel);
|
170
|
-
|
171
|
-
imageKeeper.GetComponent<KeeperManager>().SetKeeperScale(score, nextScore);
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
RefreshScoreText();
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
// Update is called once per frame
|
184
|
-
|
185
|
-
void Update () {
|
186
|
-
|
187
|
-
//まとめて生成するオーブがあれば生成
|
188
|
-
|
189
|
-
while (numOfOrb > 0)
|
190
|
-
|
191
|
-
{
|
192
|
-
|
193
|
-
Invoke("CreateNewOrb",0.1f*numOfOrb);
|
194
|
-
|
195
|
-
numOfOrb--;
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
//バックグラウンドへの移行時と復帰時(アプリ起動時も含む)に呼び出される
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
private void OnApplicationPause(bool pauseStatus)
|
208
|
-
|
209
|
-
{
|
210
|
-
|
211
|
-
if (pauseStatus)
|
212
|
-
|
213
|
-
{
|
214
|
-
|
215
|
-
//アプリがバックグラウンドへ移行
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
else
|
220
|
-
|
221
|
-
{
|
222
|
-
|
223
|
-
//バックグラウンドから復帰
|
224
|
-
|
225
|
-
//時間の復元
|
226
|
-
|
227
|
-
string time = PlayerPrefs.GetString(KEY_TIME, "");
|
228
|
-
|
229
|
-
if (time == "")
|
230
|
-
|
231
|
-
{
|
232
|
-
|
233
|
-
lastDateTime = DateTime.UtcNow;
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
else
|
238
|
-
|
239
|
-
{
|
240
|
-
|
241
|
-
long temp = Convert.ToInt64(time);
|
242
|
-
|
243
|
-
lastDateTime = DateTime.FromBinary(temp);
|
244
|
-
|
245
|
-
}
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
numOfOrb = 0;
|
250
|
-
|
251
|
-
//時間によるオーブ自動生成
|
252
|
-
|
253
|
-
TimeSpan timeSpan = DateTime.UtcNow - lastDateTime;
|
254
|
-
|
255
|
-
if (timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME))
|
256
|
-
|
257
|
-
{
|
258
|
-
|
259
|
-
while (timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME))
|
260
|
-
|
261
|
-
{
|
262
|
-
|
263
|
-
if (numOfOrb < MAX_ORB)
|
264
|
-
|
265
|
-
{
|
266
|
-
|
267
|
-
numOfOrb++;
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
timeSpan -= TimeSpan.FromSeconds(RESPAWN_TIME);
|
272
|
-
|
273
|
-
}
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
}
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
//新しいオーブの生成
|
284
|
-
|
285
|
-
public void CreateNewOrb()
|
286
|
-
|
287
|
-
{
|
288
|
-
|
289
|
-
lastDateTime = DateTime.UtcNow;
|
290
|
-
|
291
|
-
if (currentOrb >= MAX_ORB)
|
292
|
-
|
293
|
-
{
|
294
|
-
|
295
|
-
return;
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
CreateOrb();
|
300
|
-
|
301
|
-
currentOrb++;
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
SaveGameData();
|
306
|
-
|
307
|
-
}
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
//オーブ生成
|
312
|
-
|
313
|
-
public void CreateOrb()
|
314
|
-
|
315
|
-
{
|
316
|
-
|
317
|
-
GameObject orb = (GameObject)Instantiate(orbPrefab);
|
318
|
-
|
319
|
-
orb.transform.SetParent(canvasGame.transform, false);
|
320
|
-
|
321
|
-
orb.transform.localPosition = new Vector3(
|
322
|
-
|
323
|
-
UnityEngine.Random.Range (-100.0f, 100.0f),
|
324
|
-
|
325
|
-
UnityEngine.Random.Range (-300.0f, -450.0f),
|
326
|
-
|
327
|
-
0f);
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
orb.GetComponent<OrbManager>().Flyorb();
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
//ボールアニメーション
|
336
|
-
|
337
|
-
StartCoroutine("ClickAnim");//"ClickAnim"のコルーチンを呼ぶ.
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
}
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
//オーブ入手
|
350
|
-
|
351
|
-
public void GetOrb()
|
352
|
-
|
353
|
-
{
|
354
|
-
|
355
|
-
score += 1;
|
356
|
-
|
357
|
-
//キーパー画像切り替えメソッド挿入予定
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
//レベルアップ値を超えないように制限
|
362
|
-
|
363
|
-
if (score > nextScore)
|
364
|
-
|
365
|
-
{
|
366
|
-
|
367
|
-
score = nextScore;
|
368
|
-
|
369
|
-
}
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
KeeperLevelUp();
|
374
|
-
|
375
|
-
RefreshScoreText();
|
376
|
-
|
377
|
-
imageKeeper.GetComponent<KeeperManager>().SetKeeperScale(score, nextScore);
|
378
|
-
|
379
|
-
SaveGameData();
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
}
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
//スコアテキスト更新
|
392
|
-
|
393
|
-
void RefreshScoreText()
|
394
|
-
|
395
|
-
{
|
396
|
-
|
397
|
-
textScore.GetComponent<Text>().text =
|
398
|
-
|
399
|
-
score + "GOAL";
|
400
|
-
|
401
|
-
}
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
//キーパーのレベル管理
|
406
|
-
|
407
|
-
void KeeperLevelUp()
|
408
|
-
|
409
|
-
{
|
410
|
-
|
411
|
-
if (score >= nextScore)
|
412
|
-
|
413
|
-
{
|
414
|
-
|
415
|
-
if (keeperLevel < MAX_LEVEL)
|
416
|
-
|
417
|
-
{
|
418
|
-
|
419
|
-
keeperLevel++;
|
420
|
-
|
421
|
-
score = 0;
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
KeeperLevelUpEffect();
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
nextScore = nextScoreTable[keeperLevel];
|
430
|
-
|
431
|
-
imageKeeper.GetComponent<KeeperManager>().SetKeeperPicture(keeperLevel);
|
432
|
-
|
433
|
-
}
|
434
|
-
|
435
|
-
}
|
436
|
-
|
437
|
-
}
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
//レベルアップ時の演出
|
442
|
-
|
443
|
-
void KeeperLevelUpEffect()
|
444
|
-
|
445
|
-
{
|
446
|
-
|
447
|
-
GameObject trophy = (GameObject)Instantiate(trophyPrefab);
|
448
|
-
|
449
|
-
trophy.transform.SetParent(canvasGame.transform, false);
|
450
|
-
|
451
|
-
trophy.transform.SetSiblingIndex(5);
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
Destroy(trophy, 0.5f);
|
456
|
-
|
457
|
-
}
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
//ゲームデータをセーブ
|
462
|
-
|
463
|
-
void SaveGameData()
|
464
|
-
|
465
|
-
{
|
466
|
-
|
467
|
-
PlayerPrefs.SetInt(KEY_SCORE, score);
|
468
|
-
|
469
|
-
PlayerPrefs.SetInt(KEY_LEVEL,keeperLevel);
|
470
|
-
|
471
|
-
PlayerPrefs.SetInt(KEY_ORB,currentOrb);
|
472
|
-
|
473
|
-
PlayerPrefs.SetString(KEY_TIME,lastDateTime.ToBinary().ToString());
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
PlayerPrefs.Save();
|
480
|
-
|
481
|
-
}```
|
482
|
-
|
483
|
-
|
484
|
-
|
485
481
|
|
486
482
|
|
487
483
|
有識者の方、どうぞよろしくお願い致します。
|
6
コードブロック作成
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
5
コードボックス作成
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,9 @@
|
|
54
54
|
|
55
55
|
### 現在のScript
|
56
56
|
|
57
|
+
|
58
|
+
|
57
|
-
|
59
|
+
```
|
58
60
|
|
59
61
|
using System.Collections;
|
60
62
|
|
@@ -476,9 +478,9 @@
|
|
476
478
|
|
477
479
|
PlayerPrefs.Save();
|
478
480
|
|
479
|
-
}
|
481
|
+
}```
|
480
|
-
|
481
|
-
|
482
|
+
|
483
|
+
|
482
484
|
|
483
485
|
|
484
486
|
|
4
コードブロック作成
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,9 @@
|
|
54
54
|
|
55
55
|
### 現在のScript
|
56
56
|
|
57
|
+
'''
|
58
|
+
|
57
|
-
sing System.Collections;
|
59
|
+
using System.Collections;
|
58
60
|
|
59
61
|
using System.Collections.Generic;
|
60
62
|
|
@@ -376,19 +378,7 @@
|
|
376
378
|
|
377
379
|
|
378
380
|
|
379
|
-
|
381
|
+
|
380
|
-
|
381
|
-
if ((score == nextScore) && (keeperLevel == MAX_LEVEL))
|
382
|
-
|
383
|
-
{
|
384
|
-
|
385
|
-
//ClearEffect();
|
386
|
-
|
387
|
-
}
|
388
|
-
|
389
|
-
currentOrb--;
|
390
|
-
|
391
|
-
*/
|
392
382
|
|
393
383
|
|
394
384
|
|
@@ -464,19 +454,7 @@
|
|
464
454
|
|
465
455
|
}
|
466
456
|
|
467
|
-
|
457
|
+
|
468
|
-
|
469
|
-
/*void ClearEffect()
|
470
|
-
|
471
|
-
{
|
472
|
-
|
473
|
-
GameObject ??= (GameObject)Instantiate(??);
|
474
|
-
|
475
|
-
??.transform.SetParent(canvasGame.transform, false);
|
476
|
-
|
477
|
-
}*/
|
478
|
-
|
479
|
-
|
480
458
|
|
481
459
|
//ゲームデータをセーブ
|
482
460
|
|
@@ -500,7 +478,7 @@
|
|
500
478
|
|
501
479
|
}
|
502
480
|
|
503
|
-
|
481
|
+
'''
|
504
482
|
|
505
483
|
|
506
484
|
|
3
Scriptの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,6 +52,456 @@
|
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
+
### 現在のScript
|
56
|
+
|
57
|
+
sing System.Collections;
|
58
|
+
|
59
|
+
using System.Collections.Generic;
|
60
|
+
|
61
|
+
using UnityEngine;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
using UnityEngine.UI;
|
66
|
+
|
67
|
+
using System;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
public class GameManager : MonoBehaviour {
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
//定数定義
|
76
|
+
|
77
|
+
private const int MAX_ORB = 5000; //オーブ最大数
|
78
|
+
|
79
|
+
private const int RESPAWN_TIME = 15; //オーブが発生する秒数
|
80
|
+
|
81
|
+
private const int MAX_LEVEL = 5; //最大キーパーレベル
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
//データセーブ用キー
|
86
|
+
|
87
|
+
private const string KEY_SCORE = "SCORE"; //スコア
|
88
|
+
|
89
|
+
private const string KEY_LEVEL = "LEVEL"; //レベル
|
90
|
+
|
91
|
+
private const string KEY_ORB = "ORB"; //オーブ数
|
92
|
+
|
93
|
+
private const string KEY_TIME = "TIME"; //時間
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
//オブジェクト参照
|
98
|
+
|
99
|
+
public GameObject orbPrefab; //オーブプレハブ
|
100
|
+
|
101
|
+
public GameObject trophyPrefab; //トロフィープレハブ
|
102
|
+
|
103
|
+
public GameObject canvasGame; //ゲームキャンバス
|
104
|
+
|
105
|
+
public GameObject textScore; //スコアテキスト
|
106
|
+
|
107
|
+
public GameObject imageKeeper; //キーパー
|
108
|
+
|
109
|
+
public float clickrate = 0.5f;
|
110
|
+
|
111
|
+
public GameObject ball;
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
//メンバ変数
|
116
|
+
|
117
|
+
private int score = 0; //現在のスコア
|
118
|
+
|
119
|
+
private int nextScore = 400; //レベルアップまでに必要なスコア
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
private int currentOrb = 0; //現在のオーブ数
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
private int keeperLevel = 0; //キーパーのレベル
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
private DateTime lastDateTime; //前回オーブを生成した瞬間
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
private int[] nextScoreTable = new int[] { 100,200,300,400,500 }; //レベルアップ値
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
private int numOfOrb; //まとめて生成するオーブの数
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
// Use this for initialization
|
144
|
+
|
145
|
+
void Start () {
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
//データ削除メソッド
|
150
|
+
|
151
|
+
//PlayerPrefs.DeleteAll();
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
//初期設定
|
156
|
+
|
157
|
+
score = PlayerPrefs.GetInt(KEY_SCORE, 0);
|
158
|
+
|
159
|
+
keeperLevel = PlayerPrefs.GetInt(KEY_LEVEL, 0);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
nextScore = nextScoreTable[keeperLevel];
|
164
|
+
|
165
|
+
imageKeeper.GetComponent<KeeperManager>().SetKeeperPicture(keeperLevel);
|
166
|
+
|
167
|
+
imageKeeper.GetComponent<KeeperManager>().SetKeeperScale(score, nextScore);
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
RefreshScoreText();
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
// Update is called once per frame
|
180
|
+
|
181
|
+
void Update () {
|
182
|
+
|
183
|
+
//まとめて生成するオーブがあれば生成
|
184
|
+
|
185
|
+
while (numOfOrb > 0)
|
186
|
+
|
187
|
+
{
|
188
|
+
|
189
|
+
Invoke("CreateNewOrb",0.1f*numOfOrb);
|
190
|
+
|
191
|
+
numOfOrb--;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
//バックグラウンドへの移行時と復帰時(アプリ起動時も含む)に呼び出される
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
private void OnApplicationPause(bool pauseStatus)
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
if (pauseStatus)
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
//アプリがバックグラウンドへ移行
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
else
|
216
|
+
|
217
|
+
{
|
218
|
+
|
219
|
+
//バックグラウンドから復帰
|
220
|
+
|
221
|
+
//時間の復元
|
222
|
+
|
223
|
+
string time = PlayerPrefs.GetString(KEY_TIME, "");
|
224
|
+
|
225
|
+
if (time == "")
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
lastDateTime = DateTime.UtcNow;
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
else
|
234
|
+
|
235
|
+
{
|
236
|
+
|
237
|
+
long temp = Convert.ToInt64(time);
|
238
|
+
|
239
|
+
lastDateTime = DateTime.FromBinary(temp);
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
numOfOrb = 0;
|
246
|
+
|
247
|
+
//時間によるオーブ自動生成
|
248
|
+
|
249
|
+
TimeSpan timeSpan = DateTime.UtcNow - lastDateTime;
|
250
|
+
|
251
|
+
if (timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME))
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
while (timeSpan >= TimeSpan.FromSeconds(RESPAWN_TIME))
|
256
|
+
|
257
|
+
{
|
258
|
+
|
259
|
+
if (numOfOrb < MAX_ORB)
|
260
|
+
|
261
|
+
{
|
262
|
+
|
263
|
+
numOfOrb++;
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
timeSpan -= TimeSpan.FromSeconds(RESPAWN_TIME);
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
//新しいオーブの生成
|
280
|
+
|
281
|
+
public void CreateNewOrb()
|
282
|
+
|
283
|
+
{
|
284
|
+
|
285
|
+
lastDateTime = DateTime.UtcNow;
|
286
|
+
|
287
|
+
if (currentOrb >= MAX_ORB)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
return;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
CreateOrb();
|
296
|
+
|
297
|
+
currentOrb++;
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
SaveGameData();
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
//オーブ生成
|
308
|
+
|
309
|
+
public void CreateOrb()
|
310
|
+
|
311
|
+
{
|
312
|
+
|
313
|
+
GameObject orb = (GameObject)Instantiate(orbPrefab);
|
314
|
+
|
315
|
+
orb.transform.SetParent(canvasGame.transform, false);
|
316
|
+
|
317
|
+
orb.transform.localPosition = new Vector3(
|
318
|
+
|
319
|
+
UnityEngine.Random.Range (-100.0f, 100.0f),
|
320
|
+
|
321
|
+
UnityEngine.Random.Range (-300.0f, -450.0f),
|
322
|
+
|
323
|
+
0f);
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
orb.GetComponent<OrbManager>().Flyorb();
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
//ボールアニメーション
|
332
|
+
|
333
|
+
StartCoroutine("ClickAnim");//"ClickAnim"のコルーチンを呼ぶ.
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
//オーブ入手
|
346
|
+
|
347
|
+
public void GetOrb()
|
348
|
+
|
349
|
+
{
|
350
|
+
|
351
|
+
score += 1;
|
352
|
+
|
353
|
+
//キーパー画像切り替えメソッド挿入予定
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
//レベルアップ値を超えないように制限
|
358
|
+
|
359
|
+
if (score > nextScore)
|
360
|
+
|
361
|
+
{
|
362
|
+
|
363
|
+
score = nextScore;
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
KeeperLevelUp();
|
370
|
+
|
371
|
+
RefreshScoreText();
|
372
|
+
|
373
|
+
imageKeeper.GetComponent<KeeperManager>().SetKeeperScale(score, nextScore);
|
374
|
+
|
375
|
+
SaveGameData();
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
/*//ゲームクリア判定
|
380
|
+
|
381
|
+
if ((score == nextScore) && (keeperLevel == MAX_LEVEL))
|
382
|
+
|
383
|
+
{
|
384
|
+
|
385
|
+
//ClearEffect();
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
currentOrb--;
|
390
|
+
|
391
|
+
*/
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
//スコアテキスト更新
|
400
|
+
|
401
|
+
void RefreshScoreText()
|
402
|
+
|
403
|
+
{
|
404
|
+
|
405
|
+
textScore.GetComponent<Text>().text =
|
406
|
+
|
407
|
+
score + "GOAL";
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
//キーパーのレベル管理
|
414
|
+
|
415
|
+
void KeeperLevelUp()
|
416
|
+
|
417
|
+
{
|
418
|
+
|
419
|
+
if (score >= nextScore)
|
420
|
+
|
421
|
+
{
|
422
|
+
|
423
|
+
if (keeperLevel < MAX_LEVEL)
|
424
|
+
|
425
|
+
{
|
426
|
+
|
427
|
+
keeperLevel++;
|
428
|
+
|
429
|
+
score = 0;
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
KeeperLevelUpEffect();
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
nextScore = nextScoreTable[keeperLevel];
|
438
|
+
|
439
|
+
imageKeeper.GetComponent<KeeperManager>().SetKeeperPicture(keeperLevel);
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
}
|
444
|
+
|
445
|
+
}
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
//レベルアップ時の演出
|
450
|
+
|
451
|
+
void KeeperLevelUpEffect()
|
452
|
+
|
453
|
+
{
|
454
|
+
|
455
|
+
GameObject trophy = (GameObject)Instantiate(trophyPrefab);
|
456
|
+
|
457
|
+
trophy.transform.SetParent(canvasGame.transform, false);
|
458
|
+
|
459
|
+
trophy.transform.SetSiblingIndex(5);
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
Destroy(trophy, 0.5f);
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
//寺が最高レベル
|
468
|
+
|
469
|
+
/*void ClearEffect()
|
470
|
+
|
471
|
+
{
|
472
|
+
|
473
|
+
GameObject ??= (GameObject)Instantiate(??);
|
474
|
+
|
475
|
+
??.transform.SetParent(canvasGame.transform, false);
|
476
|
+
|
477
|
+
}*/
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
//ゲームデータをセーブ
|
482
|
+
|
483
|
+
void SaveGameData()
|
484
|
+
|
485
|
+
{
|
486
|
+
|
487
|
+
PlayerPrefs.SetInt(KEY_SCORE, score);
|
488
|
+
|
489
|
+
PlayerPrefs.SetInt(KEY_LEVEL,keeperLevel);
|
490
|
+
|
491
|
+
PlayerPrefs.SetInt(KEY_ORB,currentOrb);
|
492
|
+
|
493
|
+
PlayerPrefs.SetString(KEY_TIME,lastDateTime.ToBinary().ToString());
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
PlayerPrefs.Save();
|
500
|
+
|
501
|
+
}
|
502
|
+
|
503
|
+
|
504
|
+
|
55
505
|
|
56
506
|
|
57
507
|
有識者の方、どうぞよろしくお願い致します。
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
Scriptについてもですが、そもそもの構成要素などにも不安を抱えています。
|
10
10
|
|
11
11
|
まずは実装までの考え方を「文字で」理解したいです。
|
12
|
+
|
13
|
+
最終地点は、ゲーム内通貨を消費してアイテムを購入するシステムの構築です。
|
12
14
|
|
13
15
|
|
14
16
|
|
@@ -32,6 +34,8 @@
|
|
32
34
|
|
33
35
|
・アイテムは大きく分けて2種類(1クリック当たりの生産を増やす物、自動生成ぺースを高める物)
|
34
36
|
|
37
|
+
・ゲーム内で生産したゲーム内通貨を消費してアイテムを購入
|
38
|
+
|
35
39
|
・レベルマックス、アンロックはグレーアウト
|
36
40
|
|
37
41
|
・アイテム購入の際は「購入しますか?はいorいいえ」のようなシーンは設けず、クリック後すぐに購入・実装
|
1
初心者マークの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|