added comments and organized project files

This commit is contained in:
djkellerman
2025-03-28 17:39:07 -04:00
parent 22f44a3f20
commit a098e8c053
84 changed files with 183 additions and 214 deletions

View File

@@ -0,0 +1,46 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LifeDisplayManager : MonoBehaviour
{
public GameObject players;
public GameObject playerPrefab;
public GameObject lifePrefab;
public Dictionary<Damageable, List<GameObject>> lifeDisplays = new Dictionary<Damageable, List<GameObject>>();
private void Start() // Creates life icons for each player
{
if (GameManager.gameMode == GameManager.GameMode.freeForAll)
{
foreach (GameObject player in GameManager.players)
{
Transform parent = Instantiate(playerPrefab, players.transform).transform;
List<GameObject> lives = new List<GameObject>();
for (int i = 0; i < player.GetComponent<Damageable>().lives; i++)
{
GameObject life = Instantiate(lifePrefab, parent);
life.transform.Find("LIFE").GetComponent<Image>().color = GameManager.playerColors[GameManager.players.IndexOf(player)];
lives.Add(life);
}
lifeDisplays.Add(player.GetComponent<Damageable>(), lives);
}
}
}
private void Update() // Updates the lives displayed based on player lives
{
foreach (Damageable damageable in lifeDisplays.Keys)
{
foreach (GameObject life in lifeDisplays[damageable])
{
life.SetActive(lifeDisplays[damageable].IndexOf(life) < damageable.lives);
}
}
}
public void HideLifeDisplay() // Hides life display
{
players.SetActive(false);
}
}