Automatic GUI Creation When players are Added.

I am trying to write an Application for Mobile Development that uses mainly the GUI system.
What I have is a button to add player to the game, and when it is added the GUI will automatically scale to fit each player on screen (Atleast down to a minimum size). What I cant seem to figure out is how to have a GUI generate to fill the rest of the screen when another player is added.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MTGCounterGUI : MonoBehaviour 
{
	public int numOfPlayers;
	public int numOfMonsters;
	public int healthCount;
	public int poisonCount;
	public int monsterCounter;
	public bool canInput;
	
	public List<string> textInput;
	public List<string> playerNames;
	
	
	
	public void CountGUI ()
	{
		int i = 0;
		if(numOfPlayers >= 1){ 
			i = numOfPlayers - 1;
		} else {
			i = 0;
		}
		
		GUI.skin.GetStyle( "Label").alignment = TextAnchor.UpperCenter;
		
		GUI.BeginGroup (new Rect (0, 25, Screen.width / numOfPlayers, Screen.height), "");
		GUI.Box (new Rect (0, 0, Screen.width, Screen.height - 25), "");
		GUI.Label (new Rect (0, 10, Screen.width / numOfPlayers, 35), playerNames*);*
  •  GUI.EndGroup ();*
    
  • }*

  • public void AddPlayer ()*

  • {*

  •  int i = 0;*
    
  •  if (GUI.Button (new Rect (0, 0, 25, 25), "+")) {*
    
  •  	canInput = true;*
    
  •  	textInput.Add("Name " + i);*
    
  •  }*
    
  •  if (canInput) {*
    

textInput = GUI.TextField (new Rect (Screen.width / 4, Screen.height / 2, Screen.width / 2, 25), textInput*, 25);*

* if (Input.GetKeyDown (KeyCode.Return)) {*
_ playerNames.Add (textInput*);
numOfPlayers++;
i++;
textInput = null;
canInput = false;
}
}
}*_

* void Update(){*

* }*

* void OnGUI ()*
* {*
* AddPlayer();*

* if (numOfPlayers > 0) {*

* CountGUI ();*
* }*
* }*
}
This is what i have so far.
What happens is the first GUI re-sizes to allow for more to be created. I just don’t know where to begin to have more created.

If you have a function that draws the GUI, you can do a for loop that iterates for as many times as the player is drawn. You’ll have to be clever to place the GUI in a good location. Put this function in your AddPlayer code. However! I would suggest that all this GUI code really go directly inside of OnGUI and have the AddPlayer code only have to do with actually adding the player (not drawing the gui).

int xStart = 0;
int yStart = 0;
int maxX = 100;

for(int i = 0; i < numOfPlayers; i++) {
  if (GUI.Button (new Rect (xStart, yStart, 25, 25), "+")) {
         canInput = true;
         textInput.Add("Name " + i);
  }

  xStart += 25;

  if( xStart * i < maxX) {
    xStart = 0;
    yStart += 25;
  }    
}