So i’ve wanted to test my game today, and when i got in and made a room, i opened my pause menu and everythings broken.
And the error is
GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced).
Heres my full gui script:
void OnGUI(){
GUI.skin = guiSkin;
GUI.Label(new Rect(Screen.width-190, Screen.height-80, 190, 20), " Tab - pause menu");
GUI.color = new Color(1, 1, 1, 0.7f);
if(isPaused){
GUI.color = new Color(1, 1, 1, 0.7f);
GUI.Window (0, new Rect (Screen.width/2 - 250, Screen.height/2 - 210, 500, 500), MainMenu, "Room: " + PhotonNetwork.room.name + " | Game Mode: " + gameMode);
}
//Display round countdown timer
float roundedRestSeconds = Mathf.CeilToInt(currentRoundTime);
int displaySeconds = Mathf.FloorToInt(roundedRestSeconds % 60);
int displayMinutes = Mathf.FloorToInt((roundedRestSeconds / 60)%60);
string niceTime = string.Format("{0:00}:{1:00}", displayMinutes, displaySeconds);
GUI.Box(new Rect(Screen.width/2 - 50, 45, 100, 30), niceTime);
//Display Team Scores
if(gameMode == "TDM"){
GUILayout.BeginArea(new Rect(Screen.width/3 - 100, 45, 200, 30));
GUILayout.BeginHorizontal("box", GUILayout.Width(200), GUILayout.Height(30));
GUI.color = team_1_Color;
GUILayout.Label(team_1.teamName + ":");
GUILayout.Space(5);
GUI.color = Color.white;
GUILayout.Label(team1Score.ToString());
GUILayout.EndHorizontal();
GUILayout.EndArea();
GUILayout.BeginArea(new Rect(Screen.width - Screen.width/3 - 100, 45, 200, 30));
GUILayout.BeginHorizontal("box", GUILayout.Width(200), GUILayout.Height(30));
GUI.color = team_2_Color;
GUILayout.Label(team_2.teamName + ":");
GUILayout.Space(5);
GUI.color = Color.white;
GUILayout.Label(team2Score.ToString());
GUILayout.EndHorizontal();
GUILayout.EndArea();
}else{
GUI.color = Color.white;
GUI.Box(new Rect(Screen.width/2 - 150, 80, 300, 30), "Leading Player: " + leadingPlayer);
}
GUI.color = Color.white;
if(roundEnded){
GUI.Box(new Rect(Screen.width/2 - 200, Screen.height/2 - 100, 400, 30), finalText);
}
//Fade black screen when returning to Lobby
FadeScreen();
}
void MainMenu (int windowID) {
GUI.FocusWindow(windowID);
GUILayout.Space (10);
GUILayout.BeginHorizontal();
Resolutions();
QualityWindow();
GUI.color = Color.white;
GUILayout.Space (15);
GUILayout.BeginVertical();
//Select Team to Join
if(gameMode == "TDM"){
//Team 1
if((string)PhotonNetwork.player.customProperties["TeamName"] == team_1.teamName
|| (!Player && (string)PhotonNetwork.player.customProperties["TeamName"] != "Spectators" || roundEnded)){
GUI.enabled = false;
}else{
GUI.enabled = true;
}
if(GUILayout.Button(team_1.teamName)){
//Kill current player if exist
if(!Player){
SpawnPlayer(team_1.teamName);
}else{
SwapTeams(team_1.teamName);
}
isPaused = false;
//Player joined team, notify everyone
gameObject.SendMessage("PlayerJoinedTeam", team_1.teamName, SendMessageOptions.DontRequireReceiver);
}
//Team 2
if((string)PhotonNetwork.player.customProperties["TeamName"] == team_2.teamName
|| (!Player && (string)PhotonNetwork.player.customProperties["TeamName"] != "Spectators" || roundEnded)){
GUI.enabled = false;
}else{
GUI.enabled = true;
}
if(GUILayout.Button(team_2.teamName)){
//Kill current player if exist
if(!Player){
SpawnPlayer(team_2.teamName);
}else{
SwapTeams(team_2.teamName);
}
isPaused = false;
//Player joined team, notify everyone
gameObject.SendMessage("PlayerJoinedTeam", team_2.teamName, SendMessageOptions.DontRequireReceiver);
}
}else{
//Join game with Deathmatch mode
if(Player || (string)PhotonNetwork.player.customProperties["TeamName"] != "Spectators"){
GUI.enabled = false;
}else{
GUI.enabled = true;
}
if(GUILayout.Button("Join")){
//Kill current player if exist
if(!Player){
SpawnPlayer(team_1.teamName);
}else{
SwapTeams(team_1.teamName);
}
isPaused = false;
//Player joined team, notify everyone
gameObject.SendMessage("PlayerJoinedTeam", "The War", SendMessageOptions.DontRequireReceiver);
}
}
GUI.enabled = true;
if(Player){
if(GUILayout.Button("Resume")){
isPaused = false;
}
}
if(GUILayout.Button("Leave Room")){
LeaveRoom();
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.Space (10);
GUILayout.BeginHorizontal();
if(playerList){
GUI.color = new Color(0, 20, 0, 0.6f);
}else{
GUI.color = Color.white;
}
if(GUILayout.Button("Player List", GUILayout.Width(150), GUILayout.Height(25))){
playerList = true;
}
if(!playerList){
GUI.color = new Color(0, 20, 0, 0.6f);
}else{
GUI.color = Color.white;
}
if(GUILayout.Button("Controls", GUILayout.Width(150), GUILayout.Height(25))){
playerList = false;
}
GUILayout.EndHorizontal();
GUILayout.Space (5);
GUI.color = Color.white;
scroll3 = GUILayout.BeginScrollView(scroll3, GUILayout.Width(480), GUILayout.Height(300));
if(!playerList){
//Show controls
GUI.color = new Color(20, 20,0, 0.6f);
GUILayout.Label("Escape - Pause Menu");
GUILayout.Label("P - Fullscreen");
GUILayout.Label("T - Chat / Enter - send");
GUILayout.Label("C - crouch");
GUILayout.Label("Left Ctrl - prone");
GUILayout.Label("LMB - fire");
GUILayout.Label("RMB - aim");
GUILayout.Label("F - weapon pick up");
GUILayout.Label("R - reload");
GUILayout.Label("Left Shift - run");
GUILayout.Label("Space - jump");
GUILayout.Label("1/2 - weapon change");
GUILayout.Label("While selected STW-25 press G for flashlight");
}else{
//Show player list***
GUI.color = new Color(1,1,1,0.8f);
if(gameMode == "TDM"){
//Display Team 1 **************************************************************************
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUI.color = team_1_Color;
GUILayout.Label(team_1.teamName);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
foreach(PhotonPlayer player in allPlayers){
if((string)player.customProperties["TeamName"] == team_1.teamName){
if(PhotonNetwork.player.name == player.name){
GUI.color = Color.yellow;
}else{
GUI.color = Color.white;
}
GUILayout.BeginHorizontal("box");{
GUILayout.Label(player.name, GUILayout.Width(150));
GUILayout.Label("Kills: " + ((int)player.customProperties["Kills"]).ToString(), GUILayout.Width(115));
GUILayout.Label("Deaths: " + ((int)player.customProperties["Deaths"]).ToString(), GUILayout.Width(115));
GUILayout.FlexibleSpace();
if(player.customProperties["Ping"] != null){
GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
}
GUILayout.EndHorizontal();}
}
}
//*************************************************************************************
//Display Team 2 **************************************************************************
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUI.color = team_2_Color;
GUILayout.Label(team_2.teamName);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
foreach(PhotonPlayer player in allPlayers){
if((string)player.customProperties["TeamName"] == team_2.teamName){
if(PhotonNetwork.player.name == player.name){
GUI.color = Color.yellow;
}else{
GUI.color = Color.white;
}
GUILayout.BeginHorizontal("box");{
GUILayout.Label(player.name, GUILayout.Width(150));
GUILayout.Label("Kills: " + ((int)player.customProperties["Kills"]).ToString(), GUILayout.Width(115));
GUILayout.Label("Deaths: " + ((int)player.customProperties["Deaths"]).ToString(), GUILayout.Width(115));
GUILayout.FlexibleSpace();
if(player.customProperties["Ping"] != null){
GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
}
GUILayout.EndHorizontal();}
}
}
//*************************************************************************************
}else{
//If game mode is Deathmatch, display all players **************************************************
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUI.color = Color.green;
GUILayout.Label("All Players");
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
foreach(PhotonPlayer player in allPlayers){
if((string)player.customProperties["TeamName"] != "Spectators"){
if(PhotonNetwork.player.name == player.name){
GUI.color = Color.yellow;
}else{
GUI.color = Color.white;
}
GUILayout.BeginHorizontal("box");{
GUILayout.Label(player.name, GUILayout.Width(150));
GUILayout.Label("Kills: " + ((int)player.customProperties["Kills"]).ToString(), GUILayout.Width(115));
GUILayout.Label("Deaths: " + ((int)player.customProperties["Deaths"]).ToString(), GUILayout.Width(115));
GUILayout.FlexibleSpace();
if(player.customProperties["Ping"] != null){
GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
}
GUILayout.EndHorizontal();}
}
}
}
//Display Spctators ****************************************************************************
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUI.color = Color.green;
GUILayout.Label("- Spectators -");
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
foreach(PhotonPlayer player in allPlayers){
if((string)player.customProperties["TeamName"] == "Spectators"){
if(PhotonNetwork.player.name == player.name){
GUI.color = Color.yellow;
}else{
GUI.color = Color.white;
}
GUILayout.BeginHorizontal("box");{
GUILayout.Label(player.name);
GUILayout.FlexibleSpace();
if(player.customProperties["Ping"] != null){
GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
}
GUILayout.EndHorizontal();}
}
}
//*************************************************************************************
}
GUILayout.EndScrollView();
}
void Resolutions(){
GUILayout.BeginVertical();
GUILayout.Label("Resolution");
scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(140), GUILayout.Height(100));
GUILayout.BeginVertical();
for(int a = 0; a < resolutions.Length; a++){
if(resolutions[a].width == Screen.width && resolutions[a].height == Screen.height){
GUI.color = new Color(0, 20, 20, 0.6f);
}else{
GUI.color = new Color(20, 20, 20, 0.6f);
}
if(GUILayout.Button(resolutions[a].width + " x " + resolutions[a].height)){
resolutionIndex = a;
if(Screen.fullScreen){
Screen.SetResolution (resolutions[resolutionIndex].width,resolutions[resolutionIndex].height, true);
}
}
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.EndVertical();
}
void QualityWindow(){
//GUILayout.Space (10);
GUILayout.BeginVertical();
GUI.color = Color.white;
GUILayout.Label("Quality");
scroll2 = GUILayout.BeginScrollView(scroll2, GUILayout.Width(140), GUILayout.Height(100));
GUILayout.BeginVertical();
for (var i = 0; i < QualityNames.Length; i++){
if(QualityNames[i] == QualityNames[QualitySettings.GetQualityLevel ()]){
GUI.color = new Color(0, 20, 20, 0.6f);
}else{
GUI.color = new Color(20, 20, 20, 0.6f);
}
if (GUILayout.Button (QualityNames[i]))
QualitySettings.SetQualityLevel (i, true);
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.EndVertical();
}
void FadeScreen(){
if(fadeDir == 1){
fadeValue += fadeDir * 15 * Time.deltaTime;
fadeValue = Mathf.Clamp01(fadeValue);
GUI.color = new Color(1,1,1,fadeValue);
GUI.DrawTexture(new Rect(0,0, Screen.width, Screen.height), blackScreen);
GUI.color = Color.white;
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height/2 - 15, 150, 30), "Loading...");
}
}
And this is how i see my pause menu:
