-
Notifications
You must be signed in to change notification settings - Fork 0
/
Piano_Score.cs
56 lines (50 loc) · 1.61 KB
/
Piano_Score.cs
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
50
51
52
53
54
55
56
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Piano_Score : MonoBehaviour {
public int score;
private Piano_Question ques;
public GameObject FailScreen;
private Piano_Button resetleft;
private Piano_Button resetright;
private int SaveScore;
void Awake()
{
ques = FindObjectOfType<Piano_Question>();
resetright = GameObject.Find("RightButton").GetComponent<Piano_Button>();
resetleft = GameObject.Find("LeftButton").GetComponent<Piano_Button>();
}
public void UpdateScore(bool Correct)
{
if (Correct)
score += 1;
else
{
SaveScore = score;
score = 0;
StopGame();
}
gameObject.GetComponent<Text>().text = "Score: " + score;
}
public void StopGame()
{
ques.anim.SetBool("Playing", false);
FailScreen.SetActive(true);
FailScreen.transform.Find("Score").GetComponent<Text>().text = "Score: " + SaveScore;
if (PlayerPrefs.GetInt("Piano") < SaveScore)
{
FailScreen.transform.Find("Record").GetComponent<Text>().text = "Record " + SaveScore;
PlayerPrefs.SetInt("Piano", SaveScore);
}
else
FailScreen.transform.Find("Record").GetComponent<Text>().text = "Record: " + PlayerPrefs.GetInt("Piano");
}
public void StartGame()
{
ques.anim.SetBool("Playing", true);
FailScreen.SetActive(false);
score = 0;
resetleft.anim.SetInteger("IsCorrect", 0);
resetright.anim.SetInteger("IsCorrect", 0);
}
}