-
Notifications
You must be signed in to change notification settings - Fork 0
/
Score.cs
130 lines (80 loc) · 2.42 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Score : MonoBehaviour {
public GameObject WinCanvas;
public Text score1, score2, WinScore, Winner;
public Image player1, player2, winnerPlayer;
public Animator P1, P2, WinScene;
public int scoreP1, scoreP2, maxScore;
public int player1number, player2number, winnerNumber;
void Awake () {
scoreP1 = 0;
scoreP2 = 0;
maxScore = 11;
score1.text = scoreP1.ToString ();
score2.text = scoreP2.ToString ();
WinScore.text = maxScore.ToString ();
player1.sprite = FindObjectOfType<Selection> ().Character (1);
player2.sprite = FindObjectOfType<Selection> ().Character (2);
player1number = FindObjectOfType<Selection> ().Numbers (1);
player2number = FindObjectOfType<Selection> ().Numbers (2);
}
public void SetScore (int player) {
if (player == 1) {
scoreP1++;
score1.text = scoreP1.ToString ();
PlayAudio (1);
P1.SetBool ("Point", true);
} else {
scoreP2++;
score2.text = scoreP2.ToString ();
PlayAudio (2);
P2.SetBool ("Point", true);
}
Invoke ("StopAnim", 1.333f);
if (scoreP1 == scoreP2 && scoreP1 == (maxScore - 1)) {
maxScore++;
WinScore.text = maxScore.ToString ();
FindObjectOfType<EgoBall> ().MaxTurno (1);
}
if (scoreP1 == maxScore)
Win (1);
else if (scoreP2 == maxScore)
Win (2);
}
public void Win (int player) {
WinCanvas.SetActive (true);
Invoke ("WinIdle", 2.75f);
if (player == 1) {
winnerNumber = player1number;
winnerPlayer.sprite = player1.sprite;
Winner.text = player1.sprite.name + " Win";
} else if (player == 2) {
winnerNumber = player2number;
winnerPlayer.sprite = player2.sprite;
Winner.text = player2.sprite.name + " Win";
}
}
public void BackToMenu () {
FindObjectOfType<AudioManager> ().EgoTheme (1f);
SceneManager.LoadScene (0);
}
public void PlayAudio (int n) {
if (n == 1)
FindObjectOfType<AudioManager> ().PlayAudio ("Character" + player1number.ToString ());
else if (n == 2)
FindObjectOfType<AudioManager> ().PlayAudio ("Character" + player2number.ToString ());
else if (n == 3)
FindObjectOfType<AudioManager> ().PlayAudio ("Character" + winnerNumber.ToString ());
}
void StopAnim () {
P1.SetBool ("Point", false);
P2.SetBool ("Point", false);
}
void WinIdle () {
WinScene.SetBool ("WinIdle", true);
}
}