質問するログイン新規登録

質問編集履歴

6

書式の改善

2018/07/30 14:08

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -163,4 +163,69 @@
163
163
  エラー1
164
164
  > Assets/Scripts/ResultScene/ResultScoreController.cs(15,25): error CS0428: Cannot convert method group `GetScore' to non-delegate type `int'. Consider using parentheses to invoke the method
165
165
 
166
- エラー2
166
+ エラー2
167
+
168
+ ### 追記2
169
+ **今の状況**
170
+ ・BottomwallControllerはゲーム画面中のスコアを表示するTextにアタッチしている
171
+ ・ResultScoreControllerは結果画面の**スコア(ハイスコアではない)**にアタッチしている
172
+
173
+ ↓ゲーム画面のスコアTextにアタッチしているスクリプト
174
+ ```c#
175
+ using System.Collections;
176
+ using System.Collections.Generic;
177
+ using UnityEngine;
178
+ using UnityEngine.UI;
179
+
180
+ public class BottomwallController : MonoBehaviour {
181
+ public Text scoreText;
182
+ public static int score = 0;
183
+
184
+ public static int GetScore(){
185
+ return score;
186
+ }
187
+
188
+ void Start() {
189
+ score = 0;
190
+ scoreText.text = "0";
191
+ }
192
+ }
193
+ ```
194
+ ↓結果画面のスコアTextにアタッチしているスクリプト
195
+ ```c#
196
+ using System.Collections;
197
+ using System.Collections.Generic;
198
+ using UnityEngine;
199
+ using UnityEngine.UI;
200
+
201
+ public class ResultScoreController : MonoBehaviour {
202
+ public BottomwallController playerScript;
203
+ public Text scoreText;
204
+ public Text highScoreText; //ハイスコアを表示するText
205
+ private int highScore; //ハイスコア用変数
206
+ private string key = "HIGH SCORE"; //ハイスコアの保存先キー
207
+
208
+ void Start () {
209
+ int Rscore;
210
+ // Rscore = playerScript.GetScore;
211
+ scoreText.text = BottomwallController.score.ToString ();
212
+ highScore = PlayerPrefs.GetInt(key, 0);
213
+ //保存しておいたハイスコアをキーで呼び出し取得し保存されていなければ0になる
214
+ highScoreText.text = "HighScore:" + highScore.ToString();
215
+ //ハイスコアを表示
216
+ PlayerPrefs.GetInt(key, 0);
217
+ if (Rscore > highScore) {
218
+
219
+ highScore = Rscore;
220
+ //ハイスコア更新
221
+
222
+ PlayerPrefs.SetInt(key, highScore);
223
+ PlayerPrefs.Save ();
224
+ //ハイスコアを保存
225
+
226
+ highScoreText.text = highScore.ToString();
227
+ //ハイスコアを表示
228
+ }
229
+ }
230
+ }
231
+ ```

5

誤字

2018/07/30 14:08

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -156,5 +156,11 @@
156
156
  }
157
157
  }
158
158
  ```
159
- 変更したところえらーが2つ出ていて困っています。
159
+ 変更したところエラーが2つ出ていて困っています。
160
- ご教授願います。
160
+ ご教授願います。
161
+ > Assets/Scripts/ResultScene/ResultScoreController.cs(14,37): error CS0120: An object reference is required to access non-static member `BottomwallController.GetScore()'
162
+
163
+ エラー1
164
+ > Assets/Scripts/ResultScene/ResultScoreController.cs(15,25): error CS0428: Cannot convert method group `GetScore' to non-delegate type `int'. Consider using parentheses to invoke the method
165
+
166
+ エラー2

4

書式の改善

2018/07/30 10:24

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -63,4 +63,98 @@
63
63
  Player Scriptには何も入れられません
64
64
  ![イメージ説明](917ce6a3f67fbbac907c70cb9811de2d.png)
65
65
 
66
- ![イメージ説明](6b5ca2d13dd5686b1620e806c7f672df.png)
66
+ ![イメージ説明](6b5ca2d13dd5686b1620e806c7f672df.png)
67
+
68
+ [Unity シーン間で変数を共有する方法](http://www.project-unknown.jp/entry/2015/04/11/195351)
69
+ こちらを参考に、スクリプトを変更しました。
70
+ ```c#
71
+ using System.Collections;
72
+ using System.Collections.Generic;
73
+ using UnityEngine;
74
+ using UnityEngine.UI;
75
+
76
+ public class BottomwallController : MonoBehaviour {
77
+ public Text scoreText;
78
+ public static int score = 0;
79
+
80
+ public int GetScore(){
81
+ return score;
82
+ }
83
+
84
+ void Start() {
85
+ score = 0;
86
+ scoreText.text = "0";
87
+ }
88
+
89
+ void OnCollisionEnter2D(Collision2D other) {
90
+ string layerName = LayerMask.LayerToName(other.gameObject.layer);
91
+ if(other.gameObject.tag == "yasai") {
92
+ if (layerName == "heavy") {
93
+ score += 7;
94
+ scoreText.text = score.ToString ();
95
+ Debug.Log ("更新");
96
+ }
97
+ if (layerName == "usually") {
98
+ score += 5;
99
+ scoreText.text = score.ToString ();
100
+ Debug.Log ("更新");
101
+ }
102
+ if (layerName == "light") {
103
+ score += 3;
104
+ scoreText.text = score.ToString ();
105
+ Debug.Log ("更新");
106
+ }
107
+ }
108
+ if (other.gameObject.tag == "enemy") {
109
+ if (layerName == "heavy") {
110
+ score += -10;
111
+ scoreText.text = score.ToString ();
112
+ Debug.Log ("更新");
113
+ }
114
+ if (layerName == "usually") {
115
+ score += -7;
116
+ scoreText.text = score.ToString ();
117
+ Debug.Log ("更新");
118
+ }
119
+ if (layerName == "light") {
120
+ score += -5;
121
+ scoreText.text = score.ToString ();
122
+ Debug.Log ("更新");
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ ```
129
+ ```c#
130
+ using System.Collections;
131
+ using System.Collections.Generic;
132
+ using UnityEngine;
133
+ using UnityEngine.UI;
134
+
135
+ public class ResultScoreController : MonoBehaviour {
136
+ public BottomwallController playerScript;
137
+ public Text RscoreText;
138
+ public Text highScoreText; //ハイスコアを表示するText
139
+ private int highScore; //ハイスコア用変数
140
+ private string key = "HIGH SCORE"; //ハイスコアの保存先キー
141
+
142
+ void Start () {
143
+ int Rscore = BottomwallController.GetScore ();
144
+ Rscore = playerScript.GetScore;
145
+ RscoreText.text = Rscore.ToString ();
146
+ if (Rscore > highScore) {
147
+ highScore = Rscore;
148
+ //ハイスコア更新
149
+ PlayerPrefs.SetInt(key, highScore);
150
+ PlayerPrefs.Save ();
151
+ Debug.Log ("Save");
152
+ //ハイスコアを保存
153
+ highScoreText.text = highScore.ToString();
154
+ //ハイスコアを表示
155
+ }
156
+ }
157
+ }
158
+ ```
159
+ 変更したところえらーが2つ出ていて困っています。
160
+ ご教授願います。

3

書式の改善

2018/07/30 10:22

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -61,4 +61,6 @@
61
61
 
62
62
  ### 追記
63
63
  Player Scriptには何も入れられません
64
- ![イメージ説明](917ce6a3f67fbbac907c70cb9811de2d.png)
64
+ ![イメージ説明](917ce6a3f67fbbac907c70cb9811de2d.png)
65
+
66
+ ![イメージ説明](6b5ca2d13dd5686b1620e806c7f672df.png)

2

誤字

2018/07/30 08:38

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -59,5 +59,6 @@
59
59
  > NullReferenceException: Object reference not set to an instance of an object
60
60
  ResultScoreController.Start () (at Assets/Scripts/ResultScene/ResultScoreController.cs:15)
61
61
 
62
+ ### 追記
62
- ### 追記Player Scriptには何も入れられません
63
+ Player Scriptには何も入れられません
63
64
  ![イメージ説明](917ce6a3f67fbbac907c70cb9811de2d.png)

1

書式の改善

2018/07/30 04:08

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -57,4 +57,7 @@
57
57
  ```
58
58
  ↓エラー内容
59
59
  > NullReferenceException: Object reference not set to an instance of an object
60
- ResultScoreController.Start () (at Assets/Scripts/ResultScene/ResultScoreController.cs:15)
60
+ ResultScoreController.Start () (at Assets/Scripts/ResultScene/ResultScoreController.cs:15)
61
+
62
+ ### 追記Player Scriptには何も入れられません
63
+ ![イメージ説明](917ce6a3f67fbbac907c70cb9811de2d.png)