Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
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)) { {

...............................

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My network server doesn't work. 0 Answers

Player Instantiate in online game 1 Answer

Multiplayer camera bug - Everyone sees what last joinen player sees. 0 Answers

Testing my multiplayer character offline 0 Answers

How to use an RPC to send an animation over the network? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges