Commit 37a7a601 by Tim Reiter

only healthbars of playing players are shown.

healthbars are disabled when a player dies.
parent 769aa1ef
...@@ -15,7 +15,15 @@ public class PlayerHealth : MonoBehaviour { ...@@ -15,7 +15,15 @@ public class PlayerHealth : MonoBehaviour {
public void init(int playerNumber) public void init(int playerNumber)
{ {
string healthbarName = "HealthBar" + playerNumber; string healthbarName = "HealthBar" + playerNumber;
Debug.Log(healthbarName); string healthbarParentName = "HealthBarParent" + playerNumber; //wichtig um healthbars von nicht vorhandenen spielern auszublenden
GameObject healthbarParent = GameObject.Find(healthbarParentName);
//activate all children, which are disabled by default:
foreach (Transform child in healthbarParent.transform)
{
child.gameObject.SetActive(true);
}
healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>(); healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>();
if (name.EndsWith("(Clone)")) if (name.EndsWith("(Clone)"))
...@@ -31,6 +39,7 @@ public class PlayerHealth : MonoBehaviour { ...@@ -31,6 +39,7 @@ public class PlayerHealth : MonoBehaviour {
Debug.Log("Player " + name + " dead."); Debug.Log("Player " + name + " dead.");
alive = false; alive = false;
((GameStateTracker) Object.FindObjectOfType(typeof(GameStateTracker))).playerDied(name); ((GameStateTracker) Object.FindObjectOfType(typeof(GameStateTracker))).playerDied(name);
healthbar.gameObject.SetActive(false); //hide healthbar
Destroy(gameObject); Destroy(gameObject);
} }
} }
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment