Advertisement
johnnygoodguy2000

GameManager.cs

Apr 7th, 2024 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | Gaming | 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.     public static GameManager instance; // Define a static instance variable
  9.  
  10.     public Transform platformGenerator;
  11.     private Vector3 platformStartPoint;
  12.     public PlayerController thePlayer;
  13.     private Vector3 playerStartPoint;
  14.     private PlatformDestroyer[] platformList;
  15.  
  16.     public ScoreManager theScoreManager;
  17.  
  18.     public DeathMenu theDeathScreen;
  19.  
  20.     public bool powerupReset;
  21.  
  22.  
  23.     // Start is called before the first frame update
  24.     void Start()
  25.     {
  26.         instance = this; // Assign the current instance to the static variable
  27.  
  28.         platformStartPoint = platformGenerator.position;
  29.         playerStartPoint = thePlayer.transform.position;
  30.  
  31.         theScoreManager = FindObjectOfType<ScoreManager>();
  32.     }
  33.  
  34.     // Update is called once per frame
  35.     void Update()
  36.     {
  37.  
  38.         // Update logic here (if needed), but don't place methods here
  39.     }
  40.  
  41.     // Method to restart the game
  42.     public void RestartGame()
  43.     {
  44.         theScoreManager.scoreIncreasing = false;
  45.         thePlayer.gameObject.SetActive(false);
  46.         theDeathScreen.gameObject.SetActive(true);
  47.  
  48.        // StartCoroutine(RestartGameCo());
  49.  
  50.     }
  51.     public void Reset()
  52.     {
  53.        theDeathScreen.gameObject.SetActive(false);
  54.         platformList = FindObjectsOfType<PlatformDestroyer>();
  55.         for (int i = 0; i < platformList.Length; i++)
  56.         {
  57.             platformList[i].gameObject.SetActive(false);
  58.         }
  59.  
  60.         thePlayer.transform.position = playerStartPoint;
  61.  
  62.         platformGenerator.position = platformStartPoint;
  63.         thePlayer.gameObject.SetActive(true);
  64.  
  65.         theScoreManager.scoreCount = 0;
  66.         theScoreManager.scoreIncreasing = true;
  67.  
  68.         powerupReset = true;
  69.     }
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement