Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class GameManager : MonoBehaviour
- {
- //pausescreen is a UI panel
- [SerializeField] GameObject pauseScreen;
- private bool paused;
- //deactivate the gameobjects in the inspector
- public TextMeshProUGUI gameOverText;
- //remember to assign the on click event in the inspector. Drag in the game manager and choose the restart function.
- public Button restartButton;
- public bool isGameActive;
- private void Start()
- {
- isGameActive = true;
- }
- // Update is called once per frame
- void Update()
- {
- if(Input.GetKeyDown(KeyCode.P))
- {
- PauseGame();
- }
- }
- void PauseGame()
- {
- if (!paused)
- {
- paused = true;
- pauseScreen.SetActive(true);
- Time.timeScale = 0;
- }
- else
- {
- paused = false;
- pauseScreen.SetActive(false);
- Time.timeScale = 1;
- }
- }
- public void UpdateLives(int livesToChange)
- {
- lives += livesToChange;
- livesText.text = "Lives: " + lives;
- if (lives <= 0)
- {
- GameOver();
- }
- }
- public void GameOver()
- {
- gameOverText.gameObject.SetActive(true);
- isGameActive = false;
- restartButton.gameObject.SetActive(true);
- }
- public void RestartGame()
- {
- SceneManager.LoadScene(SceneManager.GetActiveScene().name);
- }
- public void ReturnToMainMenu()
- {
- SceneManager.LoadScene(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement