-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreManager.cs
More file actions
49 lines (43 loc) · 1.23 KB
/
ScoreManager.cs
File metadata and controls
49 lines (43 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
public Text scoreText; // スコア表示用のText
private int score; // スコアの変数
void Start()
{
score = 0; // スコアを初期化
UpdateScoreText(); // スコア表示を更新
}
private void OnCollisionEnter(Collision collision)
{
// 衝突カウントを増やす
AddScore();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.R) && startFlag = True )
{
score = 0;
UpdateScoreText(); // スコア表示を更新
startFlag = False;
DelUpdateScoreText();
}
UpdateScoreText();
}
// スコアを加算するメソッド
public void AddScore()
{
score += 100; // スコアを100加算
UpdateScoreText(); // スコア表示を更新
}
// スコア表示を更新するメソッド
private void UpdateScoreText()
{
scoreText.text = "Score: " + score; // テキストを更新
}
private void DelUpdateScoreText()
{
scoreText.text = " " ; // テキストを更新
}
}