回答編集履歴

1

わかりやすく

2019/11/09 02:18

投稿

snowshink
snowshink

スコア138

test CHANGED
@@ -6,6 +6,56 @@
6
6
 
7
7
  スコアオブジェクトをシーン読み込みで破棄させないようにしたらどうでしょうか。
8
8
 
9
+ ```Unity
10
+
11
+ Start(){
12
+
13
+ score = GameObject.Find("score");
14
+
9
- `DontDestoyOnLoad(score);`
15
+ DontDestoyOnLoad(score);
16
+
17
+ }
18
+
19
+ ```
10
20
 
11
21
  これで結果が保持され続けるのではないでしょうか。
22
+
23
+
24
+
25
+ 気になったのですが、スコア表示するテキストオブジェクトとスコアを保持するオブジェクトを別々にする
26
+
27
+ 必要はないのでは。
28
+
29
+
30
+
31
+ ```Unity
32
+
33
+ Text score;
34
+
35
+ public int score_current = 0;
36
+
37
+
38
+
39
+ Start(){
40
+
41
+ score = GetComponent<Text>();
42
+
43
+ DontDestoyOnLoad(this.gameObject);
44
+
45
+ }I
46
+
47
+
48
+
49
+ public void IncreaseScore(){
50
+
51
+ score_current++;
52
+
53
+ score.text = score_current;
54
+
55
+ }
56
+
57
+ ```
58
+
59
+ こう変更してscoreにはめて?ください。
60
+
61
+ これで`SceneManager.LoadScene("GameClearScene");`しても結果は表示され続けます。