Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class GameManager : MonoBehaviour
  7. {
  8. [SerializeField]
  9. private bool _isGameOver = false;
  10. [SerializeField]
  11. public bool _isCoOpMode = false;
  12. [SerializeField]
  13. private GameObject CoOpPlayers;
  14. [SerializeField]
  15. private GameObject _pauseMenu;
  16. private Animator _pauseAnim;
  17.  
  18.  
  19. private void Start()
  20. {
  21. _pauseAnim = GameObject.Find("pause_menu").GetComponent<Animator>();
  22. _pauseAnim.updateMode = AnimatorUpdateMode.UnscaledTime;
  23. }
  24. private void Update()
  25. {
  26. if (Input.GetKeyDown(KeyCode.R) && _isGameOver == true)
  27. {
  28. if (_isCoOpMode == false)
  29. {
  30. SceneManager.LoadScene(1);
  31. }
  32. else
  33. {
  34. SceneManager.LoadScene(2);
  35. }
  36. if (_isCoOpMode == true)
  37. {
  38. Instantiate(CoOpPlayers, Vector3.zero, Quaternion.identity);
  39. }
  40. }
  41.  
  42. if (Input.GetKeyDown(KeyCode.Escape))
  43. {
  44. Application.Quit();
  45. }
  46.  
  47. if (Input.GetKeyDown(KeyCode.M) && _isGameOver == true)
  48. {
  49. SceneManager.LoadScene(0);
  50. }
  51.  
  52. if (Input.GetKeyDown(KeyCode.P))
  53. {
  54. //This functionality could be used to slow down, speed up, and even stop time could be used in other games.
  55. Time.timeScale = 0f;
  56. _pauseMenu.SetActive(true);
  57. _pauseAnim.SetBool("isPaused", true);
  58. }
  59. }
  60. public void GameOver()
  61. {
  62. _isGameOver = true;
  63. }
  64.  
  65. public void ResumeGame()
  66. {
  67. Time.timeScale = 1f;
  68. _pauseMenu.SetActive(false);
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement