Files
Crash-Course/Assets/Scripts/PlayerLives.cs

43 lines
979 B
C#
Raw Normal View History

using UnityEngine;
public class PlayerLives : MonoBehaviour
{
public int maxLives = 3;
public int currentLives;
private void Start()
{
2025-02-17 18:23:05 -05:00
if (GameManager.gameMode == GameManager.GameMode.freeForAll)
{
currentLives = maxLives;
}
else //add more gamemodes and their lives here
{
currentLives = 0;
}
}
public void PlayerDied()
{
2025-02-17 18:23:05 -05:00
if (GameManager.gameMode == GameManager.GameMode.freeForAll)
{
currentLives--;
if (currentLives <= 0)
{
//add Game over sequence;
}
else
{
RespawnPlayer();
}
}
}
private void RespawnPlayer()
{
RespawnOnTriggerEnter respawnScript = GetComponent<RespawnOnTriggerEnter>();
if (respawnScript != null)
{
transform.position = respawnScript.spawnPoint;
}
}
}