/* * ------------------------------------------------------------------------ * Description: This class handles player health system * Author: Eli Simpkins-Simmonds * ------------------------------------------------------------------------ */ using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerHealth : MonoBehaviour { public int maxHealth = 100; // Maximum health of the player private int currentHealth; // Current health of the player private Vector2 spawnPoint; // Spawn point where the player will respawn private TeleportManager teleportManager; // Reference to the TeleportManager void Start() { currentHealth = maxHealth; // Initialize current health to maximum health teleportManager = FindObjectOfType(); // Find the TeleportManager in the scene spawnPoint = transform.position; // Set the initial spawn point to the player's starting position } public void TakeDamage(int damage) { currentHealth -= damage; // Reduce the current health by the damage amount if (currentHealth <= 0) // Check if the player's health is depleted { Die(); // Call the Die method to respawn the player } } void Die() { // Respawn the player at the updated spawn point transform.position = spawnPoint; // Set the player's position to the spawn point currentHealth = maxHealth; // Reset the player's health to maximum } public void UpdateSpawnPoint(Vector2 newSpawnPoint) { spawnPoint = newSpawnPoint; // Update the spawn point to a new location } }