質問編集履歴
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
### 現状
|
2
2
|
ほしいキャラを押してコイン(アイテム)を持っていないとbuydaialogが出るようにしている
|
3
3
|
switch文を使って買う(buy)ボタンと閉じる(back)ボタンに0と1を設定している
|
4
|
-
|
4
|
+
現状一つ買うとすべて変えてしまいアイテムがマイナスになってしまう
|
5
5
|
### 実現したいこと
|
6
6
|
ほしいキャラを押して出たダイアログで買うを押すとそのキャラが買えるようにしたい
|
7
7
|
### 試したこと
|
1
修正改善
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
キャラを買うのに一つのボタンで買うキャラを分けたい
|
body
CHANGED
@@ -1,25 +1,23 @@
|
|
1
1
|
### 現状
|
2
|
-
キャラ
|
2
|
+
ほしいキャラを押してコイン(アイテム)を持っていないとbuydaialogが出るようにしている
|
3
|
-
|
3
|
+
switch文を使って買う(buy)ボタンと閉じる(back)ボタンに0と1を設定している
|
4
|
-
|
4
|
+
|
5
5
|
### 実現したいこと
|
6
|
-
一つのスクリプトにまとめてきれいにしたい
|
7
|
-
|
6
|
+
ほしいキャラを押して出たダイアログで買うを押すとそのキャラが買えるようにしたい
|
8
|
-
###
|
7
|
+
### 試したこと
|
9
|
-
|
8
|
+
switch分の中にswitch文やif文を作ってみたけどうまくいかなかった
|
10
|
-
|
9
|
+
### 該当スクリプト
|
11
10
|
```unity
|
11
|
+
買うダイアログコード
|
12
|
+
public Button buy;
|
13
|
+
public Button back;
|
14
|
+
public GameObject buydialog;
|
15
|
+
public GameObject[] charactor;
|
12
16
|
|
13
|
-
public class CharaClick2 : MonoBehaviour
|
14
|
-
{
|
15
|
-
public GameObject gemdialog;
|
16
|
-
|
17
17
|
// Start is called before the first frame update
|
18
18
|
void Start()
|
19
19
|
{
|
20
20
|
PlayerPrefs.GetInt("TotalGem");
|
21
|
-
PlayerPrefs.GetInt("Chara");
|
22
|
-
PlayerPrefs.GetInt("Charactor2");
|
23
21
|
}
|
24
22
|
|
25
23
|
// Update is called once per frame
|
@@ -27,49 +25,60 @@
|
|
27
25
|
{
|
28
26
|
|
29
27
|
}
|
30
|
-
|
31
|
-
public void OnClick()
|
28
|
+
public void OnClick(int number)
|
32
29
|
{
|
33
|
-
|
30
|
+
switch (number)
|
34
31
|
{
|
32
|
+
case 0:
|
33
|
+
if (charactor[0])
|
34
|
+
{
|
35
|
+
PlayerPrefs.SetInt("Chara", 1);
|
36
|
+
PlayerPrefs.SetInt("Charactor1", 1);
|
37
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
38
|
+
buydialog.SetActive(false);
|
39
|
+
}
|
40
|
+
if (charactor[1])
|
41
|
+
{
|
35
|
-
|
42
|
+
PlayerPrefs.SetInt("Chara", 2);
|
36
|
-
|
43
|
+
PlayerPrefs.SetInt("Charactor2", 1);
|
44
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
37
|
-
|
45
|
+
buydialog.SetActive(false);
|
46
|
+
}
|
47
|
+
if (charactor[2])
|
48
|
+
{
|
38
|
-
|
49
|
+
PlayerPrefs.SetInt("Chara", 3);
|
50
|
+
PlayerPrefs.SetInt("Charactor3", 1);
|
51
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
52
|
+
buydialog.SetActive(false);
|
53
|
+
}
|
54
|
+
break;
|
55
|
+
case 1:
|
56
|
+
buydialog.SetActive(false);
|
57
|
+
break;
|
39
58
|
}
|
40
|
-
|
41
|
-
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
42
|
-
{
|
43
|
-
//////////ここをbuydialog.SetActive(true);に変える予定/////////////
|
44
|
-
PlayerPrefs.SetInt("Chara", 2);
|
45
|
-
PlayerPrefs.SetInt("Charactor2", 1);
|
46
|
-
//タイトルシーン読み込み
|
47
|
-
SceneManager.LoadScene("Title");
|
48
|
-
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
49
|
-
}
|
50
|
-
/////////////////////////////////////////////////////////////////
|
51
|
-
if (PlayerPrefs.GetInt("Charactor2") == 0)
|
52
|
-
{
|
53
|
-
gemdialog.SetActive(true);
|
54
|
-
return;
|
55
|
-
}
|
56
59
|
}
|
57
60
|
}
|
61
|
+
|
58
62
|
```
|
59
|
-
買うダイアログ
|
60
63
|
```unity
|
61
|
-
|
64
|
+
キャラ選択コード
|
62
|
-
|
63
|
-
public class
|
65
|
+
public class Charaselect : MonoBehaviour
|
64
66
|
{
|
65
|
-
public Button buy;
|
66
|
-
public
|
67
|
+
public GameObject[] charactor;
|
68
|
+
public GameObject gemdialog;
|
67
69
|
public GameObject buydialog;
|
68
70
|
|
69
71
|
// Start is called before the first frame update
|
70
72
|
void Start()
|
71
73
|
{
|
74
|
+
/////////////////いらないコードがあると思う////////////////////////////
|
72
75
|
PlayerPrefs.GetInt("TotalGem");
|
76
|
+
PlayerPrefs.GetInt("Chara");
|
77
|
+
PlayerPrefs.GetInt("Charactor1");
|
78
|
+
PlayerPrefs.GetInt("Charactor2");
|
79
|
+
PlayerPrefs.GetInt("Charactor3");
|
80
|
+
PlayerPrefs.GetInt("Charactor4");
|
81
|
+
///////////////////////////////////////////////////////////
|
73
82
|
}
|
74
83
|
|
75
84
|
// Update is called once per frame
|
@@ -77,20 +86,110 @@
|
|
77
86
|
{
|
78
87
|
|
79
88
|
}
|
89
|
+
|
80
|
-
public void OnClick()
|
90
|
+
public void OnClick(int number)
|
81
91
|
{
|
82
|
-
|
92
|
+
switch (number)
|
83
93
|
{
|
94
|
+
case 0:
|
95
|
+
PlayerPrefs.SetInt("Chara", 0);
|
96
|
+
//タイトルシーン読み込み
|
84
|
-
|
97
|
+
SceneManager.LoadScene("Title");
|
85
|
-
|
98
|
+
break;
|
86
99
|
|
100
|
+
|
87
|
-
|
101
|
+
case 1:
|
102
|
+
if (PlayerPrefs.GetInt("Charactor1") == 1)
|
88
|
-
|
103
|
+
{
|
89
|
-
|
104
|
+
PlayerPrefs.SetInt("Chara", 1);
|
105
|
+
|
106
|
+
//タイトルシーン読み込み
|
107
|
+
SceneManager.LoadScene("Title");
|
108
|
+
}
|
109
|
+
|
110
|
+
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
111
|
+
{
|
112
|
+
buydialog.SetActive(true);
|
113
|
+
}
|
114
|
+
|
115
|
+
if (PlayerPrefs.GetInt("Charactor1") == 0)
|
116
|
+
{
|
117
|
+
gemdialog.SetActive(true);
|
118
|
+
return;
|
119
|
+
}
|
120
|
+
break;
|
121
|
+
|
122
|
+
case 2:
|
123
|
+
if (PlayerPrefs.GetInt("Charactor2") == 1)
|
124
|
+
{
|
125
|
+
PlayerPrefs.SetInt("Chara", 2);
|
126
|
+
|
127
|
+
//タイトルシーン読み込み
|
128
|
+
SceneManager.LoadScene("Title");
|
129
|
+
}
|
130
|
+
|
131
|
+
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
132
|
+
{
|
133
|
+
buydialog.SetActive(true);
|
134
|
+
}
|
135
|
+
|
136
|
+
if (PlayerPrefs.GetInt("Charactor2") == 0)
|
137
|
+
{
|
138
|
+
gemdialog.SetActive(true);
|
139
|
+
return;
|
140
|
+
}
|
141
|
+
break;
|
142
|
+
|
143
|
+
case 3:
|
144
|
+
if (PlayerPrefs.GetInt("Charactor3") == 1)
|
145
|
+
{
|
146
|
+
PlayerPrefs.SetInt("Chara", 3);
|
147
|
+
|
148
|
+
//タイトルシーン読み込み
|
149
|
+
SceneManager.LoadScene("Title");
|
150
|
+
}
|
151
|
+
|
152
|
+
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
153
|
+
{
|
154
|
+
PlayerPrefs.SetInt("Chara", 3);
|
90
|
-
|
155
|
+
PlayerPrefs.SetInt("Charactor3", 1);
|
156
|
+
//タイトルシーン読み込み
|
157
|
+
SceneManager.LoadScene("Title");
|
91
|
-
|
158
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
159
|
+
}
|
160
|
+
|
161
|
+
if (PlayerPrefs.GetInt("Charactor3") == 0)
|
162
|
+
{
|
163
|
+
gemdialog.SetActive(true);
|
164
|
+
return;
|
165
|
+
}
|
166
|
+
break;
|
167
|
+
|
168
|
+
case 4:
|
169
|
+
if (PlayerPrefs.GetInt("Charactor4") == 1)
|
170
|
+
{
|
171
|
+
PlayerPrefs.SetInt("Chara", 4);
|
172
|
+
|
173
|
+
//タイトルシーン読み込み
|
174
|
+
SceneManager.LoadScene("Title");
|
175
|
+
}
|
176
|
+
|
177
|
+
if (PlayerPrefs.GetInt("TotalGem") >= 30)
|
178
|
+
{
|
179
|
+
PlayerPrefs.SetInt("Chara", 4);
|
180
|
+
PlayerPrefs.SetInt("Charactor4", 1);
|
181
|
+
//タイトルシーン読み込み
|
182
|
+
SceneManager.LoadScene("Title");
|
183
|
+
PlayerPrefs.SetInt("TotalGem", PlayerPrefs.GetInt("TotalGem") - 30);
|
184
|
+
}
|
185
|
+
|
186
|
+
if (PlayerPrefs.GetInt("Charactor4") == 0)
|
187
|
+
{
|
188
|
+
gemdialog.SetActive(true);
|
189
|
+
return;
|
190
|
+
}
|
191
|
+
break;
|
92
192
|
}
|
93
193
|
}
|
94
194
|
}
|
95
|
-
|
96
195
|
```
|