pt2
This commit is contained in:
@@ -3,6 +3,10 @@ using UnityEngine;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager Instance { get; private set; }
|
||||
public int maxLives = 3;
|
||||
public int currentLives;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartGame();
|
||||
@@ -12,14 +16,17 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
if (gameMode == GameMode.freeForAll)
|
||||
{
|
||||
currentLives = maxLives;
|
||||
StartFreeForAll();
|
||||
}
|
||||
if (gameMode == GameMode.keepAway)
|
||||
{
|
||||
currentLives = 1;
|
||||
StartKeepAway();
|
||||
}
|
||||
if (gameMode == GameMode.obstacleCourse)
|
||||
{
|
||||
currentLives = 1;
|
||||
StartObstacleCourse();
|
||||
}
|
||||
}
|
||||
@@ -33,7 +40,7 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
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>();
|
||||
|
||||
@@ -54,6 +61,7 @@ public class GameManager : MonoBehaviour
|
||||
player.transform.position = spawnPosition;
|
||||
}
|
||||
}
|
||||
|
||||
private void StartObstacleCourse()
|
||||
{
|
||||
foreach (GameObject player in players)
|
||||
@@ -61,4 +69,44 @@ public class GameManager : MonoBehaviour
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user