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.