This commit is contained in:
djkellerman
2025-02-28 14:01:55 -05:00
parent 5fc2455f97
commit 189aab2fd8

View File

@@ -3,6 +3,10 @@ using UnityEngine;
public class GameManager : MonoBehaviour public class GameManager : MonoBehaviour
{ {
public static GameManager Instance { get; private set; }
public int maxLives = 3;
public int currentLives;
private void Start() private void Start()
{ {
StartGame(); StartGame();
@@ -12,14 +16,17 @@ public class GameManager : MonoBehaviour
{ {
if (gameMode == GameMode.freeForAll) if (gameMode == GameMode.freeForAll)
{ {
currentLives = maxLives;
StartFreeForAll(); StartFreeForAll();
} }
if (gameMode == GameMode.keepAway) if (gameMode == GameMode.keepAway)
{ {
currentLives = 1;
StartKeepAway(); StartKeepAway();
} }
if (gameMode == GameMode.obstacleCourse) if (gameMode == GameMode.obstacleCourse)
{ {
currentLives = 1;
StartObstacleCourse(); StartObstacleCourse();
} }
} }
@@ -33,7 +40,7 @@ public class GameManager : MonoBehaviour
public static GameMode gameMode = GameMode.freeForAll; public static GameMode gameMode = GameMode.freeForAll;
public static string map = "Platformer With Headroom"; //is called for in playermanager but should probably be removed. public static string map = "Platformer With Headroom"; //called for in PlayerManager and should be changed to load from here instead
public static List<GameObject> players = new List<GameObject>(); public static List<GameObject> players = new List<GameObject>();
@@ -54,6 +61,7 @@ public class GameManager : MonoBehaviour
player.transform.position = spawnPosition; player.transform.position = spawnPosition;
} }
} }
private void StartObstacleCourse() private void StartObstacleCourse()
{ {
foreach (GameObject player in players) foreach (GameObject player in players)
@@ -61,4 +69,44 @@ public class GameManager : MonoBehaviour
player.transform.position = spawnPosition; player.transform.position = spawnPosition;
} }
} }
public void PlayerDied(GameObject player)
{
if (gameMode == GameMode.freeForAll)
{
currentLives--;
if (currentLives <= 0)
{
GameOver(player);
}
else
{
RespawnPlayer(player);
}
}
if (gameMode == GameMode.keepAway)
{
}
if (gameMode == GameMode.obstacleCourse)
{
}
}
private void RespawnPlayer(GameObject player)
{
RespawnOnTriggerEnter respawnScript = player.GetComponent<RespawnOnTriggerEnter>();
if (respawnScript != null)
{
player.transform.position = respawnScript.spawnPoint;
player.GetComponent<Damageable>().ResetDamage();
}
}
private void GameOver(GameObject player)
{
// Disable player controls and show game over screen
player.SetActive(false);
}
} }