質問編集履歴

1

スクリプトの表示

2021/02/20 06:21

投稿

banana.red
banana.red

スコア4

test CHANGED
File without changes
test CHANGED
@@ -2,15 +2,163 @@
2
2
 
3
3
  コードscore.cs
4
4
 
5
+ using System.Collections;
6
+
7
+ using System.Collections.Generic;
8
+
9
+ using UnityEngine;
10
+
11
+ using UnityEngine.UI;
12
+
13
+
14
+
15
+ public class Score : MonoBehaviour
16
+
17
+ {
18
+
19
+ public Text scoreText;
20
+
21
+ public Text highScoreText;
22
+
23
+ private int score;
24
+
25
+ private int highScore;
26
+
27
+ private string highScoreKey = "highScore";
28
+
29
+
30
+
31
+ void Start()
32
+
33
+ {
34
+
35
+ Initialize();
36
+
37
+ }
38
+
39
+
40
+
41
+ void Update()
42
+
43
+ {
44
+
45
+
46
+
47
+ if (highScore < score)
48
+
49
+ {
50
+
51
+ highScore = score;
52
+
53
+ }
54
+
55
+
56
+
57
+ scoreText.text = score.ToString();
58
+
59
+ highScoreText.text = highScore.ToString();
60
+
61
+ }
62
+
63
+
64
+
65
+ private void Initialize()
66
+
67
+ {
68
+
69
+ score = 0;
70
+
5
- ![イメージ説明](b89a249eee43ecb3de439922e5c03c68.png)
71
+ highScore = PlayerPrefs.GetInt(highScoreKey, 0);
72
+
6
-
73
+ }
74
+
75
+
76
+
77
+ public void AddPoint(int point)
78
+
79
+ {
80
+
81
+ score = score + point;
82
+
83
+ }
84
+
85
+
86
+
87
+
88
+
89
+ public void Save()
90
+
91
+ {
92
+
93
+
94
+
7
- ![イメージ説明](54a7e24c66ec357cdee44c5aa2584d85.png)
95
+ PlayerPrefs.SetInt(highScoreKey, highScore);
8
-
96
+
9
- ![イメージ説明](a1291b80c43447dd56377634e6c39a20.png)
97
+ PlayerPrefs.Save();
98
+
99
+
100
+
101
+
102
+
103
+ Initialize();
104
+
105
+ }
106
+
107
+ }
108
+
109
+
10
110
 
11
111
  コードblock.cs
12
112
 
113
+ public class Block : MonoBehaviour
114
+
115
+ {
116
+
117
+ // Start is called before the first frame update
118
+
119
+ void Start()
120
+
121
+ {
122
+
123
+
124
+
125
+ }
126
+
127
+
128
+
129
+ // Update is called once per frame
130
+
131
+ void Update()
132
+
133
+ {
134
+
135
+
136
+
137
+ }
138
+
13
- ![イメージ説明](e5bcc34943897d33476ce7da671108c7.png)
139
+ private void OnCollisionEnter(Collision collision)
140
+
141
+ {
142
+
143
+ Destroy(this.gameObject);
144
+
145
+ /*if (collision.gameObject.tag == "Ball")
146
+
147
+ {
148
+
149
+
150
+
151
+ FindObjectOfType<Score>().AddPoint(10);
152
+
153
+ Destroy(this.gameObject);
154
+
155
+
156
+
157
+ }*/
158
+
159
+ }
160
+
161
+ }
14
162
 
15
163
  ```### 前提・実現したいこと
16
164
 
@@ -58,4 +206,4 @@
58
206
 
59
207
 
60
208
 
61
- ここにより詳細情報を記載てください
209
+ block.csのif文は動かかったのでコメントアウトました