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/UIManager.cs

63 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
public class UIManager : MonoBehaviour
{
public TextMeshProUGUI Health;
public static UIManager instance;
public CharacterController player;
public GameObject GameOverPanel;
public CameraFollow cameraFollow;
1 week ago
bool isGameOver = false;
float Score;
public TextMeshProUGUI ScoreText;
private void Awake()
{
instance = this;
}
private void Start()
{
UpdateHealth();
1 week ago
StartCoroutine(ScoreUpdateRoutine());
}
IEnumerator ScoreUpdateRoutine()
{
while(!isGameOver)
{
Score += Time.fixedDeltaTime;
ScoreText.text = Mathf.FloorToInt(Score).ToString();
yield return new WaitForSeconds(Time.fixedDeltaTime);
}
}
public void UpdateHealth()
{
1 week ago
if (!isGameOver)
{
1 week ago
if (player.Health <= 0)
{
Health.text = "Health: 0";
GameOver();
}
else
{
Health.text = "Health: " + player.Health.ToString();
}
}
}
void GameOver()
{
1 week ago
isGameOver = true;
Destroy(player.SpineHingeJoint);
GameOverPanel.SetActive(true);
cameraFollow.isPlaying = false;
}
public void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}