質問編集履歴
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
switch文を使って買う(buy)ボタンと閉じる(back)ボタンに0と1を設定している
|
6
6
|
|
7
|
-
|
7
|
+
現状一つ買うとすべて変えてしまいアイテムがマイナスになってしまう
|
8
8
|
|
9
9
|
### 実現したいこと
|
10
10
|
|
1
修正改善
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
キャラを買うのに一つのボタンで買うキャラを分けたい
|
test
CHANGED
@@ -1,33 +1,141 @@
|
|
1
1
|
### 現状
|
2
2
|
|
3
|
-
キャラ
|
3
|
+
ほしいキャラを押してコイン(アイテム)を持っていないとbuydaialogが出るようにしている
|
4
|
-
|
4
|
+
|
5
|
-
|
5
|
+
switch文を使って買う(buy)ボタンと閉じる(back)ボタンに0と1を設定している
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
|
8
8
|
|
9
9
|
### 実現したいこと
|
10
10
|
|
11
|
-
一つのスクリプトにまとめてきれいにしたい
|
12
|
-
|
13
|
-
|
11
|
+
ほしいキャラを押して出たダイアログで買うを押すとそのキャラが買えるようにしたい
|
14
|
-
|
12
|
+
|
15
|
-
###
|
13
|
+
### 試したこと
|
14
|
+
|
16
|
-
|
15
|
+
switch分の中にswitch文やif文を作ってみたけどうまくいかなかった
|
17
|
-
|
18
|
-
|
16
|
+
|
19
|
-
|
17
|
+
### 該当スクリプト
|
20
18
|
|
21
19
|
```unity
|
22
20
|
|
23
|
-
|
21
|
+
買うダイアログコード
|
22
|
+
|
24
|
-
|
23
|
+
public Button buy;
|
24
|
+
|
25
|
+
public Button back;
|
26
|
+
|
27
|
+
public GameObject buydialog;
|
28
|
+
|
29
|
+
public GameObject[] charactor;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
// Start is called before the first frame update
|
34
|
+
|
35
|
+
void Start()
|
36
|
+
|
37
|
+
{
|
38
|
+
|
39
|
+
PlayerPrefs.GetInt("TotalGem");
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
// Update is called once per frame
|
46
|
+
|
47
|
+
void Update()
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
public void OnClick(int number)
|
56
|
+
|
57
|
+
{
|
58
|
+
|
59
|
+
switch (number)
|
60
|
+
|
61
|
+
{
|
62
|
+
|
63
|
+
case 0:
|
64
|
+
|
65
|
+
if (charactor[0])
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
PlayerPrefs.SetInt("Chara", 1);
|
70
|
+
|
71
|
+
PlayerPrefs.SetInt("Charactor1", 1);
|
72
|
+
|
73
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
74
|
+
|
75
|
+
buydialog.SetActive(false);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
if (charactor[1])
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
PlayerPrefs.SetInt("Chara", 2);
|
84
|
+
|
85
|
+
PlayerPrefs.SetInt("Charactor2", 1);
|
86
|
+
|
87
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
88
|
+
|
89
|
+
buydialog.SetActive(false);
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
if (charactor[2])
|
94
|
+
|
95
|
+
{
|
96
|
+
|
97
|
+
PlayerPrefs.SetInt("Chara", 3);
|
98
|
+
|
99
|
+
PlayerPrefs.SetInt("Charactor3", 1);
|
100
|
+
|
101
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
102
|
+
|
103
|
+
buydialog.SetActive(false);
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
break;
|
108
|
+
|
109
|
+
case 1:
|
110
|
+
|
111
|
+
buydialog.SetActive(false);
|
112
|
+
|
113
|
+
break;
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
```unity
|
126
|
+
|
127
|
+
キャラ選択コード
|
128
|
+
|
25
|
-
public class Chara
|
129
|
+
public class Charaselect : MonoBehaviour
|
26
130
|
|
27
131
|
{
|
28
132
|
|
133
|
+
public GameObject[] charactor;
|
134
|
+
|
29
135
|
public GameObject gemdialog;
|
30
136
|
|
137
|
+
public GameObject buydialog;
|
138
|
+
|
31
139
|
|
32
140
|
|
33
141
|
// Start is called before the first frame update
|
@@ -36,12 +144,22 @@
|
|
36
144
|
|
37
145
|
{
|
38
146
|
|
147
|
+
/////////////////いらないコードがあると思う////////////////////////////
|
148
|
+
|
39
149
|
PlayerPrefs.GetInt("TotalGem");
|
40
150
|
|
41
151
|
PlayerPrefs.GetInt("Chara");
|
42
152
|
|
153
|
+
PlayerPrefs.GetInt("Charactor1");
|
154
|
+
|
43
155
|
PlayerPrefs.GetInt("Charactor2");
|
44
156
|
|
157
|
+
PlayerPrefs.GetInt("Charactor3");
|
158
|
+
|
159
|
+
PlayerPrefs.GetInt("Charactor4");
|
160
|
+
|
161
|
+
///////////////////////////////////////////////////////////
|
162
|
+
|
45
163
|
}
|
46
164
|
|
47
165
|
|
@@ -58,134 +176,214 @@
|
|
58
176
|
|
59
177
|
|
60
178
|
|
61
|
-
public void OnClick()
|
179
|
+
public void OnClick(int number)
|
62
|
-
|
180
|
+
|
63
|
-
{
|
181
|
+
{
|
64
|
-
|
182
|
+
|
65
|
-
i
|
183
|
+
switch (number)
|
66
184
|
|
67
185
|
{
|
68
186
|
|
187
|
+
case 0:
|
188
|
+
|
189
|
+
PlayerPrefs.SetInt("Chara", 0);
|
190
|
+
|
191
|
+
//タイトルシーン読み込み
|
192
|
+
|
193
|
+
SceneManager.LoadScene("Title");
|
194
|
+
|
195
|
+
break;
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
case 1:
|
202
|
+
|
203
|
+
if (PlayerPrefs.GetInt("Charactor1") == 1)
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
PlayerPrefs.SetInt("Chara", 1);
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
//タイトルシーン読み込み
|
212
|
+
|
213
|
+
SceneManager.LoadScene("Title");
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
220
|
+
|
221
|
+
{
|
222
|
+
|
223
|
+
buydialog.SetActive(true);
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
if (PlayerPrefs.GetInt("Charactor1") == 0)
|
230
|
+
|
231
|
+
{
|
232
|
+
|
233
|
+
gemdialog.SetActive(true);
|
234
|
+
|
235
|
+
return;
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
break;
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
case 2:
|
244
|
+
|
245
|
+
if (PlayerPrefs.GetInt("Charactor2") == 1)
|
246
|
+
|
247
|
+
{
|
248
|
+
|
69
|
-
PlayerPrefs.SetInt("Chara", 2);
|
249
|
+
PlayerPrefs.SetInt("Chara", 2);
|
70
|
-
|
71
|
-
|
72
|
-
|
250
|
+
|
251
|
+
|
252
|
+
|
73
|
-
//タイトルシーン読み込み
|
253
|
+
//タイトルシーン読み込み
|
74
|
-
|
254
|
+
|
75
|
-
SceneManager.LoadScene("Title");
|
255
|
+
SceneManager.LoadScene("Title");
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
262
|
+
|
263
|
+
{
|
264
|
+
|
265
|
+
buydialog.SetActive(true);
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
if (PlayerPrefs.GetInt("Charactor2") == 0)
|
272
|
+
|
273
|
+
{
|
274
|
+
|
275
|
+
gemdialog.SetActive(true);
|
276
|
+
|
277
|
+
return;
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
break;
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
case 3:
|
286
|
+
|
287
|
+
if (PlayerPrefs.GetInt("Charactor3") == 1)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
PlayerPrefs.SetInt("Chara", 3);
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
//タイトルシーン読み込み
|
296
|
+
|
297
|
+
SceneManager.LoadScene("Title");
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
304
|
+
|
305
|
+
{
|
306
|
+
|
307
|
+
PlayerPrefs.SetInt("Chara", 3);
|
308
|
+
|
309
|
+
PlayerPrefs.SetInt("Charactor3", 1);
|
310
|
+
|
311
|
+
//タイトルシーン読み込み
|
312
|
+
|
313
|
+
SceneManager.LoadScene("Title");
|
314
|
+
|
315
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
if (PlayerPrefs.GetInt("Charactor3") == 0)
|
322
|
+
|
323
|
+
{
|
324
|
+
|
325
|
+
gemdialog.SetActive(true);
|
326
|
+
|
327
|
+
return;
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
break;
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
case 4:
|
336
|
+
|
337
|
+
if (PlayerPrefs.GetInt("Charactor4") == 1)
|
338
|
+
|
339
|
+
{
|
340
|
+
|
341
|
+
PlayerPrefs.SetInt("Chara", 4);
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
//タイトルシーン読み込み
|
346
|
+
|
347
|
+
SceneManager.LoadScene("Title");
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
354
|
+
|
355
|
+
{
|
356
|
+
|
357
|
+
PlayerPrefs.SetInt("Chara", 4);
|
358
|
+
|
359
|
+
PlayerPrefs.SetInt("Charactor4", 1);
|
360
|
+
|
361
|
+
//タイトルシーン読み込み
|
362
|
+
|
363
|
+
SceneManager.LoadScene("Title");
|
364
|
+
|
365
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
if (PlayerPrefs.GetInt("Charactor4") == 0)
|
372
|
+
|
373
|
+
{
|
374
|
+
|
375
|
+
gemdialog.SetActive(true);
|
376
|
+
|
377
|
+
return;
|
378
|
+
|
379
|
+
}
|
380
|
+
|
381
|
+
break;
|
76
382
|
|
77
383
|
}
|
78
384
|
|
79
|
-
|
80
|
-
|
81
|
-
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
82
|
-
|
83
|
-
{
|
84
|
-
|
85
|
-
//////////ここをbuydialog.SetActive(true);に変える予定/////////////
|
86
|
-
|
87
|
-
PlayerPrefs.SetInt("Chara", 2);
|
88
|
-
|
89
|
-
PlayerPrefs.SetInt("Charactor2", 1);
|
90
|
-
|
91
|
-
//タイトルシーン読み込み
|
92
|
-
|
93
|
-
SceneManager.LoadScene("Title");
|
94
|
-
|
95
|
-
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
/////////////////////////////////////////////////////////////////
|
100
|
-
|
101
|
-
if (PlayerPrefs.GetInt("Charactor2") == 0)
|
102
|
-
|
103
|
-
{
|
104
|
-
|
105
|
-
gemdialog.SetActive(true);
|
106
|
-
|
107
|
-
return;
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
385
|
}
|
112
386
|
|
113
387
|
}
|
114
388
|
|
115
389
|
```
|
116
|
-
|
117
|
-
買うダイアログ
|
118
|
-
|
119
|
-
```unity
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
public class Buydialog : MonoBehaviour
|
126
|
-
|
127
|
-
{
|
128
|
-
|
129
|
-
public Button buy;
|
130
|
-
|
131
|
-
public Button back;
|
132
|
-
|
133
|
-
public GameObject buydialog;
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
// Start is called before the first frame update
|
138
|
-
|
139
|
-
void Start()
|
140
|
-
|
141
|
-
{
|
142
|
-
|
143
|
-
PlayerPrefs.GetInt("TotalGem");
|
144
|
-
|
145
|
-
}
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
// Update is called once per frame
|
150
|
-
|
151
|
-
void Update()
|
152
|
-
|
153
|
-
{
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
public void OnClick()
|
160
|
-
|
161
|
-
{
|
162
|
-
|
163
|
-
if (back)
|
164
|
-
|
165
|
-
{
|
166
|
-
|
167
|
-
buydialog.SetActive(false);
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
if (buy)
|
174
|
-
|
175
|
-
{
|
176
|
-
|
177
|
-
PlayerPrefs.SetInt("Chara", 1);
|
178
|
-
|
179
|
-
PlayerPrefs.SetInt("Charactor1", 1);
|
180
|
-
|
181
|
-
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
```
|