-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlayerManager.cs
51 lines (45 loc) · 1.37 KB
/
PlayerManager.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class PlayerManager : MonoBehaviour
{
public static float playerHealth, currentScore;
public Image healthImg;
public TMP_Text scoreText, highScoreText;
public GameObject gameON, gameOFF, enemies;
// Start is called before the first frame update
void Start()
{
highScoreText.text = PlayerPrefs.GetFloat("HighScore").ToString();
}
// Update is called once per frame
void Update()
{
if (playerHealth <= 0)
GameOver();
healthImg.fillAmount = playerHealth;
scoreText.text = currentScore.ToString();
}
public void GameStart()
{
gameON.SetActive(true);
gameOFF.SetActive(false);
playerHealth = 1;
currentScore = 0;
scoreText.text = "0";
}
public void GameOver()
{
if (currentScore > PlayerPrefs.GetFloat("HighScore"))
{
PlayerPrefs.SetFloat("HighScore", currentScore);
highScoreText.text = PlayerPrefs.GetFloat("HighScore").ToString();
}
foreach(Transform child in enemies.transform)
child.gameObject.GetComponent<EnemyController>().Death();
gameON.SetActive(false);
gameOFF.SetActive(true);
}
}