GUI inside a While Loop

I have two Floats, yOffset and playerCount. I’m using PUN and trying to give a HUD for each player joined. But it seems to be putting all of the HUDs at exactly the same height… I thought if I had a while loop that checks if the current rooms player count is higher than the float I created and added to the float after running the DrawTexture it would put them at different heights, but I can’t seem to figure this out and would really appreciate some help.

public float yOffset = 0;
public float playerCount;

while (PhotonNetwork.room.playerCount > playerCount) {
            foreach (PhotonPlayer player in PhotonNetwork.playerList) {
                GUI.DrawTexture (new Rect (355, yOffset, 100, 50), HealthBar);
            }
            if(playerCount != PhotonNetwork.room.playerCount) {
                yOffset += 45;
                playerCount += 1;
            }
        }

for(int i = 0; i < PhotonNetwork.playerList.Length; i++){
			foreach (PhotonPlayer player in PhotonNetwork.playerList) {
				GUI.DrawTexture(new Rect (0, i*(60) + 10, 150, 50), HUDBox);
				GUI.DrawTexture(new Rect (0, i*(60) + 40, 150, 10), HealthBar);
				GUI.Label(new Rect (0, i*(65) + 10, 150, 50), player.name);
			}
		}

Well, I see your problem - too many loops and if statements and I don’t even know what it does. I can’t quite follow what your code actually does, never mind what goes wrong…how about you do this instead?

for(int i = 0; i < PhotonNetwork.playerList.Length; i++){
 GUI.DrawTexture(new Rect 355, i*(50+yOffset), 100, 50), HealthBar);
}

You could use PhotonNetwork.room.playerCount as well instead of playerlist.Length, but I figure this way it makes more sense if you later add something like PhotonNetwork.playerList*.someProperty in the for loop (I don’t remeber what properties player objects have in Photon and if you’d ever want to do that, but still).*