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

57 lines
1.3 KiB
C#
Raw Normal View History

2025-02-17 19:02:14 -05:00
using Unity.VisualScripting;
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;
}
2025-02-17 19:02:14 -05:00
if (GameManager.gameMode == GameManager.GameMode.keepAway)
{
2025-02-17 19:02:14 -05:00
currentLives = 1;
}
2025-02-17 19:02:14 -05:00
if (GameManager.gameMode == GameManager.GameMode.obstacleCourse)
{
currentLives = 1;
}
//add more gamemodes and their lives here
}
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();
}
}
2025-02-17 19:02:14 -05:00
if (GameManager.gameMode == GameManager.GameMode.keepAway)
{
}
if (GameManager.gameMode == GameManager.GameMode.obstacleCourse)
{
}
}
private void RespawnPlayer()
{
RespawnOnTriggerEnter respawnScript = GetComponent<RespawnOnTriggerEnter>();
if (respawnScript != null)
{
transform.position = respawnScript.spawnPoint;
}
}
}