121 lines
2.2 KiB
C#
121 lines
2.2 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
#region Statication
|
|
|
|
public static GameManager instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
DontDestroyOnLoad(this);
|
|
}
|
|
|
|
#endregion
|
|
|
|
[Header("Game Stats")]
|
|
public int continues;
|
|
public string time;
|
|
public int wave;
|
|
public int deflections;
|
|
public int projectilesShot;
|
|
public int projectilesHit;
|
|
public string accuracy;
|
|
public int livesLost;
|
|
[Header("Pause UI")]
|
|
[SerializeField] private GameObject pauseMenu;
|
|
|
|
[Header("Game Over")]
|
|
[SerializeField] private DialogueScript winCutscene;
|
|
[SerializeField] private GameObject loseUI;
|
|
[SerializeField] private StatsUI statsUI;
|
|
private bool gameOver;
|
|
|
|
public void EndGame()
|
|
{
|
|
SetPause(true);
|
|
gameOver = true;
|
|
time = TimeSpan.FromSeconds(Time.timeSinceLevelLoad).ToString(@"mm\:ss");
|
|
wave = WaveManager.instance.wave-1;
|
|
accuracy = ((float)projectilesHit / projectilesShot).ToString(@"P");
|
|
}
|
|
public void LoseGame()
|
|
{
|
|
loseUI.SetActive(true);
|
|
EndGame();
|
|
statsUI.SetUI();
|
|
}
|
|
|
|
public void WinGame()
|
|
{
|
|
EndGame();
|
|
LevelSwitcher.instance.SwitchLevel(2, winCutscene);
|
|
SetPause(false);
|
|
}
|
|
|
|
public void ExitGame()
|
|
{
|
|
LevelSwitcher.instance.SwitchLevel(0);
|
|
SetPause(false);
|
|
}
|
|
|
|
public void RestartGame()
|
|
{
|
|
LevelSwitcher.instance.SwitchLevel(1);
|
|
SetPause(false);
|
|
}
|
|
|
|
public void ContinueGame()
|
|
{
|
|
gameOver = false;
|
|
loseUI.SetActive(false);
|
|
SetPause(false);
|
|
WaveManager.instance.player.health = WaveManager.instance.player.maxHealth;
|
|
continues++;
|
|
}
|
|
|
|
public void SetPause(bool state)
|
|
{
|
|
if (state)
|
|
{
|
|
Time.timeScale = 0f;
|
|
}
|
|
else
|
|
{
|
|
Time.timeScale = 1f;
|
|
}
|
|
}
|
|
|
|
public void SetPauseMenu()
|
|
{
|
|
if (!gameOver && !DialogueManager.instance.dialogueActive)
|
|
{
|
|
if (!pauseMenu.activeSelf)
|
|
{
|
|
pauseMenu.SetActive(true);
|
|
SetPause(true);
|
|
}
|
|
else
|
|
{
|
|
pauseMenu.SetActive(false);
|
|
SetPause(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Escape)) //we need to convert this to a better input system
|
|
{
|
|
SetPauseMenu();
|
|
}
|
|
}
|
|
}
|