i have a problem wit my GUILayout

i wrote a script where i can see the health of a player but when more than 2 players connect, you see the hp of your player and the hp of the other player
so what does i have to change to see the hp of only your player?
i hope i get soon as possible a answer.
thx
jenten

public void ScoreHealth()
	{
		GUILayout.BeginArea(new Rect(Screen.width /2 - 200, Screen.height / 2-250, 400, 500));
		
		foreach(MyPlayer.player in MultiplayerManager.instance.PlayerList)
		{
			GUILayout.BeginHorizontal("box");
			GUILayout.Label("HP");
			GUILayout.BeginVertical(GUILayout.Width(150));
			GUILayout.Box(player.PlayerHealth.ToString(), GUILayout.Width(150));
			GUI.color = Color.red;
			
			GUILayout.EndHorizontal();
			
		}
		GUILayout.EndArea();
	}
	
	
}

Why not just check if the player you are looping through has a certain parameter that makes it local?

i just want a new line from these: foreach(MPPlayer player in MultiplayerManager.instance.PlayerList)

If your local player is in that list, unless you use something like a hashtable, you can't avoid looping through it

1 Answer

1

It’s hard to tell from your question but maybe try using GUI.depth. This will determine what GUI elements will be displayed “on top of” the other ones. So you could set the main player to have a lower GUI.depth value than other players. This would require each player to have a separate script to determine the depth of that script.