-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreManager.cs
61 lines (52 loc) · 1.71 KB
/
ScoreManager.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using Unity.VisualScripting;
public class ScoreManager : MonoBehaviour
{
[Header("Score Manager")]
public int kills;
public int enemyKills;
public Text playerKillCounter;
public Text enemyKillCounter;
public Text MainText;
public void Awake() //to initialize 0 to the phone everytime the game launches
{
if (PlayerPrefs.HasKey("kills"))
{
kills = PlayerPrefs.GetInt("0");
}
else if (PlayerPrefs.HasKey("enemyKills"))
{
enemyKills = PlayerPrefs.GetInt("0");
}
}
private void Update()
{
StartCoroutine(WinOrLose());
}
IEnumerator WinOrLose()
{
playerKillCounter.text = "" + kills;
enemyKillCounter.text = "" + enemyKills;
if(kills >= 10)
{
MainText.text = "Blue Team Victory";
PlayerPrefs.SetInt("kills", kills); //PlayerPrefs : a class that stores the player scores between game sessions
Time.timeScale = 0f; //stop the time -> pause the game
yield return new WaitForSeconds(5f);
SceneManager.LoadScene("TDMRoom"); //reload the scene after 5s
}
else if (enemyKills >= 10)
{
MainText.text = "Red Team Victory";
PlayerPrefs.SetInt("enemyKills", enemyKills);
Time.timeScale = 0f;
yield return new WaitForSecondsRealtime(5f);
SceneManager.LoadScene("TDMRoom");
}
yield return null;
}
}