You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FlyingFred/Assets/Scripts/UIManager.cs

62 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.SceneManagement;
public class UIManager : MonoBehaviour
{
public Image Health;
public static UIManager instance;
public CharacterController player;
public GameObject GameOverPanel;
public CameraFollow cameraFollow;
public TextMeshProUGUI ScoreText;
public TextMeshProUGUI BestScoreText;
private void Awake()
{
instance = this;
}
private void Start()
{
BestScoreUpdater();
UpdateHealth();
}
void BestScoreUpdater()
{
BestScoreText.text = PlayerPrefs.GetInt("BestScore").ToString();
}
public void UpdateHealth()
{
if (!GameManager.instance.isGameOver)
{
if (player.Health <= 0)
{
Health.fillAmount = 0;
GameOver();
}
else
{
Health.fillAmount = player.Health/100f;
//Health.text = "Health: " + player.Health.ToString();
}
}
}
public void GameOver()
{
GameManager.instance.isGameOver = true;
Destroy(player.SpineHingeJoint);
GameOverPanel.SetActive(true);
cameraFollow.isPlaying = false;
if (GameManager.instance.Score > PlayerPrefs.GetInt("BestScore"))
{
PlayerPrefs.GetInt("BestScore", (int)GameManager.instance.Score);
}
}
public void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}