using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class GameOverCanvas : MonoBehaviour{ public int enemiesKilled; public int tilesEnabled; public float timeSurvived; int finalScore; [Header("Win Canvas")] [SerializeField] GameObject winCanvas = default; [Space] [SerializeField] GameObject maxScoreText = default; [SerializeField] TextMeshProUGUI enemiesText = default; [SerializeField] TextMeshProUGUI tilesText = default; [SerializeField] TextMeshProUGUI scoreText = default; [Header("Game Over Canvas")] [SerializeField] GameObject gameOverCanvas = default; [Space] [SerializeField] GameObject gameOverMaxScoreText = default; [SerializeField] TextMeshProUGUI gameOverEnemiesText = default; [SerializeField] TextMeshProUGUI gameOverTilesText = default; [SerializeField] TextMeshProUGUI gameOverScoreText = default; public static GameOverCanvas instance; // Start is called before the first frame update void Awake(){ instance = this; } public void Win(){ PlayerPrefs.SetInt("Tutorial", 1); AudioManager.instance.Stop("Main"); Time.timeScale = 0; winCanvas.SetActive(true); enemiesText.text = enemiesKilled.ToString(); tilesText.text = tilesEnabled.ToString(); if(enemiesKilled == 0){ finalScore = Mathf.RoundToInt(2 * 8 * (tilesEnabled / 4) * (timeSurvived / 60)); }else{ finalScore = Mathf.RoundToInt(enemiesKilled * 8 * (tilesEnabled / 4) * (timeSurvived / 60)); } scoreText.text = finalScore.ToString(); if (PlayerPrefs.HasKey("MaxScore")){ if (PlayerPrefs.GetInt("MaxScore") >= finalScore){ maxScoreText.SetActive(false); }else{ PlayerPrefs.SetInt("MaxScore", finalScore); } }else{ PlayerPrefs.SetInt("MaxScore", finalScore); } } public void Lose(){ PlayerPrefs.SetInt("Tutorial", 1); Time.timeScale = 0; gameOverCanvas.SetActive(true); gameOverEnemiesText.text = enemiesKilled.ToString(); gameOverTilesText.text = tilesEnabled.ToString(); if (enemiesKilled == 0){ finalScore = Mathf.RoundToInt(2 * 8 * (tilesEnabled / 4) * (timeSurvived / 60)); }else{ finalScore = Mathf.RoundToInt(enemiesKilled * 8 * (tilesEnabled / 4) * (timeSurvived / 60)); } gameOverScoreText.text = finalScore.ToString(); if (PlayerPrefs.HasKey("MaxScore")){ if (PlayerPrefs.GetInt("MaxScore") >= finalScore){ gameOverMaxScoreText.SetActive(false); }else{ PlayerPrefs.SetInt("MaxScore", finalScore); } }else{ PlayerPrefs.SetInt("MaxScore", finalScore); } } }