回答編集履歴

2

key変更

2019/01/06 06:54

投稿

bochan2
bochan2

スコア2050

test CHANGED
@@ -40,9 +40,9 @@
40
40
 
41
41
  int m=0;
42
42
 
43
- if(PlayerPrefs.HasKey("ORB")){
43
+ if(PlayerPrefs.HasKey("SCORE")){
44
44
 
45
- m=PlayerPrefs.GetInt("ORB");
45
+ m=PlayerPrefs.GetInt("SCORE");
46
46
 
47
47
  }
48
48
 
@@ -60,7 +60,7 @@
60
60
 
61
61
  PlayerPrefs.SetInt(key,a);
62
62
 
63
- PlayerPrefs.SetInt("ORB",m);
63
+ PlayerPrefs.SetInt("SCORE",m);
64
64
 
65
65
  }
66
66
 

1

スクリプトを追加

2019/01/06 06:54

投稿

bochan2
bochan2

スコア2050

test CHANGED
@@ -2,4 +2,66 @@
2
2
 
3
3
  大まかな方針としてはゲーム内通貨をPlayerPrefsに書き込んで処理するのが良いと思います。
4
4
 
5
+
6
+
7
+
8
+
9
+ ###コード
10
+
11
+ これを好きなクラス名にして(MonoBehaviorは継承)ショップのシーンに貼り付けて下さい
12
+
13
+ UIのボタンからBuyを指定するとイベントを登録出来ます。
14
+
5
- 得点の処理部分のスクリプト追記していただければ動くコード載せれるのしい場合はお願いします。
15
+ pricesinspector画面から指定すると値段設定きます(設定とエラー吐きます
16
+
17
+ moneydialogはお金が足りないときに表示されるダイアログのgameobjectです。使う場合は閉じるボタンにイベントを設定して下さい。いらなかったら消してください
18
+
19
+
20
+
21
+ アイテムの種類が多いのであればscriptableObjectを使った方がいいと思います
22
+
23
+ ```C#
24
+
25
+ public GameObject moneydialog;
26
+
27
+ public List<int> prices;
28
+
29
+ public void Buy(int id){
30
+
31
+ int a=0;
32
+
33
+ string key="ITEM"+id;
34
+
35
+ if(PlayerPrefs.HasKey(key)){
36
+
37
+ a=PlayerPrefs.GetInt(key);
38
+
39
+ }
40
+
41
+ int m=0;
42
+
43
+ if(PlayerPrefs.HasKey("ORB")){
44
+
45
+ m=PlayerPrefs.GetInt("ORB");
46
+
47
+ }
48
+
49
+ if(m<prices[id]){
50
+
51
+ moneydialog.SetActive(true);
52
+
53
+ return;
54
+
55
+ }
56
+
57
+ m-=prices[id];
58
+
59
+ a+=1;
60
+
61
+ PlayerPrefs.SetInt(key,a);
62
+
63
+ PlayerPrefs.SetInt("ORB",m);
64
+
65
+ }
66
+
67
+ ```