Seperate GUIs for Different Players

Hello All!

At the moment I am currently making a multiplayer game. There are two teams. One human team and one controlled by the paranormal. I hoped something like this would seperate the two GUIs but at the moment they both render over each other…

function OnGUI(){

	if (teamnumber == 1)
	{
	
	GUI.Label(new Rect(10,10,250,50),"Current Objective: " + objective);	//Prints Objective
	GUI.Label(new Rect(10,30,200,50),"Sanity: " + sanity);
	
	var iconID :int;	//Checks battery charge
	if(battery > 85) iconID = 0;
	else if(battery > 75) iconID = 1;
	else if(battery > 65) iconID = 2;
	else if(battery > 50) iconID = 3;
	else if(battery > 25) iconID = 4;
	else if(battery > 0) iconID = 5;
	else iconID = 6;
	
	GUI.Label(new Rect(10,Screen.height-100,iconWidth,iconHeight),GUIContent(batteryIcons[iconID]));
	
	}
	
	else if (teamnumber == 2)
	{
	
	GUI.Label(new Rect(10,10,250,50),"Beast Test");
	
	
	}
}

Any suggestions? I am at my wits end.

I assume there are two team objects in the hierarchy, one with teamnumber 1 and one with teamnumber 2? … and if they both exist each one will render it’s attached OnGUI function hence the output of both teams UIs…

Somewhere you need to have an “activeTeam” control in whatever gameManager script you’ve got… and then your if checks in the above code need to be teamnumber == gameManager.activeTeam

All the stuff you currently have within OnGUI you should wrap into GUI.BeginGroup. You could make a method that renders the whole group and is receiving a Rect as an argument.

function DrawStuff(Rect bounds) {
    GUI.BeginGroup (bounds);
    // draw your stuff here
    GUI.EndGroup();
}

This way you could reuse this piece of code and draw the same thing twice (on different coordinates).