Files
CartoonFPS/Assets/Scripts/UIController.cs
2025-08-05 17:31:28 +01:00

53 lines
1.6 KiB
C#

using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
public class UIController : MonoBehaviour
{
public static UIController instance; // Singleton instance of UIController
private void Awake()
{
instance = this; // Assign the singleton instance
}
public TextMeshProUGUI currentAmmoText, remainingAmmoText, healthText; // Reference to the ammo text UI element
public GameObject deathScreen; // Reference to the death screen UI element
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void UpdateAmmoText(int currentAmmo, int remainingAmmo)
{
currentAmmoText.text = currentAmmo.ToString(); // Update the current ammo text
remainingAmmoText.text = "/" + remainingAmmo.ToString(); // Update the remaining ammo text
}
public void UpdateHealthText(float currentHealth)
{
healthText.text = "Health: " + Mathf.RoundToInt(currentHealth).ToString(); // Update the health text with formatted value
}
public void ShowDeathScreen()
{
deathScreen.SetActive(true);
Cursor.lockState = CursorLockMode.None; // Unlock the cursor when the death screen is shown
}
public void RestartLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void QuitGame()
{
Application.Quit(); // Quit the application
}
public void MainMenu()
{
SceneManager.LoadScene("MainMenu"); // Load the main menu scene
}
}