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.

89 lines
2.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.SceneManagement;
using MS;
public class UIManager : MonoBehaviour
{
public Image Health;
public static UIManager instance;
public CharacterController player;
public CameraFollow cameraFollow;
public TextMeshProUGUI ScoreText;
public TextMeshProUGUI BestScoreText;
public TextMeshProUGUI GameOverCurrentScore;
public Popup GameoverPanel;
public Popup MainScreen;
private void Awake()
{
instance = this;
}
private void Start()
{
BestScoreUpdater();
UpdateHealth();
MainScreen.Open();
}
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()
{
GameOverCurrentScore.text = GameManager.instance.Score.ToString();
MainScreen.Close();
GameoverPanel.Open();
GameManager.instance.isGameOver = true;
Destroy(player.SpineHingeJoint);
Health.fillAmount = 0;
//GameOverPanel.SetActive(true);
cameraFollow.isPlaying = false;
if (GameManager.instance.Score > PlayerPrefs.GetInt("BestScore"))
{
Debug.Log("Here");
PlayerPrefs.SetInt("BestScore", (int)GameManager.instance.Score);
}
}
public void Pause()
{
Time.timeScale = 0;
}
public void Resume()
{
Time.timeScale = 1;
}
public void Home()
{
Resume();
SceneManager.LoadScene("MainMenu");
}
public void Restart()
{
Resume();
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void ApplicationCloser()
{
Application.Quit();
}
}