- Home /
 
               Question by 
               TheRichardGamer · Nov 29, 2013 at 08:56 AM · 
                multiplayernetworkonlinegui-problemgui state  
              
 
              How to close multiple GUI Buttons and open other gui buttons
So, I am making a multiplayer game, and I want my players to be able to choose the team they will be playing on. And the problem is that when I start my server, I should be able to choose teams because I have a boolean that checks if the buttons for the teams is enabled or not, but it doesn't work. Why doesn't this work? Here's my script: var SwatPlayer : GameObject; var SoldierPlayer : GameObject;
 var SwatSpawn : Transform;
 var SoldierSpawn : Transform;
  
 var gameName : String = "Game";
 private var refreshing : boolean = false;
 private var hostData : HostData[];
  
 var MaxPlayers : int; 
 
 var ChoosingTeams : boolean = false;
  
  var EmptyName : boolean = false;
  
 
  
 private var RespawnText : GUIText;
  
  
 function OnGUI () {
  
 if(!Network.isClient && !Network.isServer) {
  
  gameName = GUI.TextField(Rect(Screen.width/2,Screen.height/2 -10,100,20),gameName);
  
  GUI.Label(Rect(Screen.width/2,Screen.height/2 -30,150,20),"Host a game");
 
  
 
 
 if(ChoosingTeams == true){ //Here's the if statement for the team buttons, but it doesn't work for some reason
 
      if(GUI.Button(Rect(Screen.width/2 + 60,Screen.height/2 + 50,100,20), "Join S.W.A.T")){
         
         
         spawnSwat();
         
              }
              
              
              if(GUI.Button(Rect(Screen.width/2 - 60,Screen.height/2 + 50,100,20), "Join Soldiers")){
         
         
         spawnSoldier();
         
              }
        
 
     } 
 
 
 
  
  
  if(EmptyName){
  
  GUI.Label (Rect (Screen.width/2, Screen.height/2 -12, 430, 20), "Please enter a game name, or your game won't register");
  
  }
  
 
  
  
  if (GUI.Button(Rect(Screen.width/2,Screen.height/2 + 10,100,20),"Start Server")) {
  
         if(!EmptyName){
         startServer();
         }
 }
  
  if (GUI.Button(Rect(Screen.width/2,Screen.height/2 + 30,100,20),"Refresh List")) {
         Debug.Log("Refresh");
         refreshHostList();
 }
         if(hostData) {
  
         for(var i:int = 0; i<hostData.length; i++) {
        
         if(GUI.Button(Rect(Screen.width/2,Screen.height/2 + 60,270,20),"Game: " + hostData[i].gameName)) {
                 Network.Connect(hostData[i]);
        
        
         }
        
        
 }
  
 }
  
  
 }
  
  
 }
  
  
 function Update () {
  
  
  
  if(String.IsNullOrEmpty(gameName)){
  
  EmptyName = true;
  
  }
  
   else
   
  EmptyName = false;
  
  
  
  
         if(refreshing) {
                 if(MasterServer.PollHostList().Length > 0) {           
                 refreshing = false;
                 Debug.Log(MasterServer.PollHostList().Length);
                 hostData = MasterServer.PollHostList();
                
                
                 }
        
        
         }
  
  
  
 }
  
  
 function startServer () {
  var UseNat = !Network.HavePublicAddress();
         Network.InitializeServer(32,25001, UseNat);
         MasterServer.RegisterHost(gameName, gameName, "This is a beta server");
         ChoosingTeams = true; // Here's my boolean
           
 }
        
        
        
 function OnServerInitialized () {
  
         Debug.Log("Server initialized");
         
      ChoosingTeams = true; //Here's my boolean
        
 }
  
 function OnConnectedToServer () {
         if(Network.isClient == true){
       
           ChoosingTeams = true;    //Here's my boolean   
              
         
         }
  
 }
  
 function spawnSwat () {
  
         Network.Instantiate(SwatPlayer, SwatSpawn.position, Quaternion.identity, 0);
         Debug.Log("Spawned a player in the team S.W.A.T");
 }
 
 
 function spawnSoldier () {
  
         Network.Instantiate(SoldierPlayer, SoldierSpawn.position, Quaternion.identity, 0);
         Debug.Log("Spawned a player in the team Soldiers");
 }
 
 
  
 function OnMasterServerEvent(mse:MasterServerEvent) {
  
         if(mse == MasterServerEvent.RegistrationSucceeded) {
         Debug.Log("Registered Server with name " + gameName);
        
         }
        
 }
        
        
 function refreshHostList () {
  
         MasterServer.RequestHostList(gameName);
         refreshing = true;
  
        
        
 }
 
 
 @RPC
 function ReSpawnSwat () {
 
    
     Debug.Log("A player died, the player will respawn in 5 seconds...");
     yield WaitForSeconds(5);
     Network.Instantiate(SwatPlayer, SwatSpawn.position, Quaternion.identity, 0);
    
 }
 
 
 @RPC
 function ReSpawnSoldier () {
 
    
     Debug.Log("A player died, the player will respawn in 5 seconds...");
     yield WaitForSeconds(5);
     Network.Instantiate(SoldierPlayer, SoldierSpawn.position, Quaternion.identity, 0);
    
 }
 
 
 
 
 
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by belvita · Nov 29, 2013 at 02:01 PM
make a bool variable and set it to true on start
then if u click on a GUI button make it false
if(Clicked==false) {
 //do nothing
} else if(GUI.Button(new Rect (Screen.width / 2-75,Screen.height / 2-160,30,30),sand)) { {
...............................
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                