Advertisement
johnnygoodguy2000

LevelManager.cs

Apr 25th, 2024 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | Gaming | 0 0
  1.  
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class LevelManager : MonoBehaviour
  7. {
  8.     public GameObject currentCheckpoint; //Get current checkpoint
  9.  
  10.     private PlayerController player; //Get player
  11.  
  12.     public GameObject deathPartical; // Death particle
  13.  
  14.     public GameObject respawnPartical; // Respawn particle
  15.     public int pointPenaltyOnDeath; // Points penalty on death
  16.  
  17.     public float respawnTime; // Time to wait before respawning
  18.  
  19.     private CameraController cameraController; //Get CameraController
  20.  
  21.     //private float gravityStore;//Gravity
  22.  
  23.     public HealthManager healthManager; //Get HealthManager
  24.  
  25.     public HealthManager playerHealthManager;//Get HealthManager
  26.  
  27.    
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.     // Start is called before the first frame update
  35.     void Start()
  36.     {
  37.         player = FindObjectOfType<PlayerController>();//Get player
  38.  
  39.         cameraController = FindObjectOfType<CameraController>();//Get CameraController
  40.  
  41.         healthManager = FindObjectOfType<HealthManager>();//Get HealthManager
  42.  
  43.         //playerHealthManager = player.GetComponent<HealthManager>();//Get HealthManager
  44.  
  45.        
  46.     }
  47.  
  48.     // Update is called once per frame
  49.     void Update()
  50.     {
  51.        
  52.     }
  53.  
  54.     public void RespawnPlayer()
  55.     {
  56.         StartCoroutine("RespawnPlayerCoroutine");//Starts coroutine
  57.        
  58.     }
  59.  
  60.     public IEnumerator RespawnPlayerCoroutine()//Coroutine
  61.  
  62.     {
  63.         Instantiate(deathPartical, player.transform.position, player.transform.rotation);//Spawns death particle
  64.  
  65.         player.enabled = false;//Disables player
  66.         player.GetComponent<Renderer>().enabled = false; // Disable the player's renderer
  67.  
  68.  
  69.         cameraController.isFollowing = false;
  70.  
  71.         //gravityStore = player.GetComponent<Rigidbody2D>().gravityScale;
  72.  
  73.         //player.GetComponent<Rigidbody2D>().gravityScale = 0f;
  74.  
  75.         //player.GetComponent<Rigidbody2D>().velocity = Vector2.zero;//Resets velocity may be unnecessary
  76.  
  77.         ScoreManager.AddPoints(-pointPenaltyOnDeath);
  78.         Debug.Log("Player Respawn");
  79.  
  80.  
  81.         yield return new WaitForSeconds(respawnTime);//Waits for respawn time
  82.  
  83.         //player.GetComponent<Rigidbody2D>().gravityScale = gravityStore;
  84.  
  85.  
  86.  
  87.         player.transform.position = currentCheckpoint.transform.position; // Respawn the player
  88.  
  89.         player.enabled = true;//Resets player
  90.         player.GetComponent<Renderer>().enabled = true; // Enable the player's renderer
  91.  
  92.         player.knockbackCount = 0;//Resets knockback
  93.  
  94.         healthManager.FullHealth();//Resets health
  95.  
  96.         healthManager.isDead = false; // Reset the isDead flag
  97.  
  98.         cameraController.isFollowing = true;//Resets camera
  99.  
  100.         Instantiate(respawnPartical, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);//Resets particle
  101.     }
  102.  
  103.    
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement