質問編集履歴
1
スクリプトの表示
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,10 +1,84 @@
|
|
1
1
|
``````
|
2
2
|
コードscore.cs
|
3
|
+
using System.Collections;
|
4
|
+
using System.Collections.Generic;
|
5
|
+
using UnityEngine;
|
6
|
+
using UnityEngine.UI;
|
7
|
+
|
8
|
+
public class Score : MonoBehaviour
|
9
|
+
{
|
10
|
+
public Text scoreText;
|
11
|
+
public Text highScoreText;
|
12
|
+
private int score;
|
13
|
+
private int highScore;
|
14
|
+
private string highScoreKey = "highScore";
|
15
|
+
|
16
|
+
void Start()
|
17
|
+
{
|
18
|
+
Initialize();
|
19
|
+
}
|
20
|
+
|
21
|
+
void Update()
|
22
|
+
{
|
23
|
+
|
24
|
+
if (highScore < score)
|
25
|
+
{
|
26
|
+
highScore = score;
|
27
|
+
}
|
28
|
+
|
29
|
+
scoreText.text = score.ToString();
|
30
|
+
highScoreText.text = highScore.ToString();
|
31
|
+
}
|
32
|
+
|
33
|
+
private void Initialize()
|
34
|
+
{
|
35
|
+
score = 0;
|
3
|
-
|
36
|
+
highScore = PlayerPrefs.GetInt(highScoreKey, 0);
|
37
|
+
}
|
38
|
+
|
39
|
+
public void AddPoint(int point)
|
40
|
+
{
|
41
|
+
score = score + point;
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
public void Save()
|
46
|
+
{
|
47
|
+
|
4
|
-
|
48
|
+
PlayerPrefs.SetInt(highScoreKey, highScore);
|
5
|
-
|
49
|
+
PlayerPrefs.Save();
|
50
|
+
|
51
|
+
|
52
|
+
Initialize();
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
6
56
|
コードblock.cs
|
57
|
+
public class Block : MonoBehaviour
|
58
|
+
{
|
59
|
+
// Start is called before the first frame update
|
60
|
+
void Start()
|
61
|
+
{
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
// Update is called once per frame
|
66
|
+
void Update()
|
67
|
+
{
|
68
|
+
|
69
|
+
}
|
7
|
-
|
70
|
+
private void OnCollisionEnter(Collision collision)
|
71
|
+
{
|
72
|
+
Destroy(this.gameObject);
|
73
|
+
/*if (collision.gameObject.tag == "Ball")
|
74
|
+
{
|
75
|
+
|
76
|
+
FindObjectOfType<Score>().AddPoint(10);
|
77
|
+
Destroy(this.gameObject);
|
78
|
+
|
79
|
+
}*/
|
80
|
+
}
|
81
|
+
}
|
8
82
|
```### 前提・実現したいこと
|
9
83
|
|
10
84
|
ここに質問の内容を詳しく書いてください。
|
@@ -28,4 +102,4 @@
|
|
28
102
|
|
29
103
|
### 補足情報(FW/ツールのバージョンなど)
|
30
104
|
|
31
|
-
|
105
|
+
block.csのif文は動かなかったのでコメントアウトしました。
|