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
1
Question by 03gramat · Nov 07, 2013 at 03:10 PM · guieditorbuildbuild-error

GUI not working in Build?

I have been struggling to work out the problem here.

I am toggling certain GUI elements depending on which buttons you press using booleans. Here is my script:

 @script ExecuteInEditMode()
 
 var gameName : String = "thetestgame123";
 
 var refreshing = false;
 var hostData : HostData[];
 
 var playerPrefab : GameObject;
 
 var create = false;
 var joining = false;
 
 var serverName = "";
 var serverPass = "";
 
 var clientPass = "";
  
 function OnGUI () {
 
     if(!Network.isClient && !Network.isServer) {
     
         if(!create && !joining){
     
             if (GUI.Button(Rect(Screen.width/2,Screen.height/2,100,20),"Create Game")) {
                 
                 create = true;
             }
     
              if (GUI.Button(Rect(Screen.width/2,Screen.height/2 + 30,100,20),"Find Game")) {
                 
                 joining = true;
                 refreshHostList();
             }
         }
         
         if (create){
             
             if (GUI.Button(Rect(Screen.width/2,Screen.height/2 + 60,100,20),"Create")) {
     
                 startServer();
             }
             
             GUI.Label(Rect (Screen.width/2 - 50,Screen.height/2,100,20),"Server Name:");
             GUI.Label(Rect (Screen.width/2 + 75,Screen.height/2,100,20),"Password:");
                 
             serverName = GUI.TextField (Rect (Screen.width/2 - 60,Screen.height/2 + 30,100,20), serverName, 25);
             serverPass = GUI.PasswordField (Rect (Screen.width/2 + 60,Screen.height/2 + 30,100,20), serverPass, "*"[0], 25);
             
             if (GUI.Button(Rect(Screen.width/1.2,Screen.height/20,100,20),"Back")) {
 
                    create = false;
             }
         }
         
         if (joining){
         
             if(hostData) {
     
                 for(var i:int = 0; i < hostData.length; i++) {
     
                     GUI.Label(Rect(Screen.width/2 - 50,Screen.height/2 + 60,100,20),hostData[i].gameName);
                     
                     clientPass = GUI.PasswordField (Rect (Screen.width/2 + 60,Screen.height/2 + 30,100,20), clientPass, "*"[0], 25);
             
                     if (GUI.Button(Rect(Screen.width/2,Screen.height/2 + 60,100,20),"Join")) {
     
                         Network.Connect(hostData[i]);
                     }
                 }
             }
             
             if (GUI.Button(Rect(Screen.width/1.2,Screen.height/20,100,20),"Back")) {
 
                    joining = false;
             }
             
             if(!hostData) {
             
                 joining = false;
             }
         }
         
         if (GUI.Button(Rect(Screen.width/20,Screen.height/20,100,20),"Quit")) {
 
                Application.Quit();
         }
     }
 }
 
 function Update () {
 
     if(refreshing) {
 
         if(MasterServer.PollHostList().Length > 0) {
 
             refreshing = false;
             hostData = MasterServer.PollHostList();
         }
     }
 }
 
 function startServer () {
     
     Network.incomingPassword = serverPass;
     Network.InitializeServer(32,25001, !Network.HavePublicAddress);
     MasterServer.RegisterHost(gameName, serverName, "this is a tutorial");
 }
 
 function OnServerInitialized () {
     
     DontDestroyOnLoad (transform.gameObject);
     
     Application.LoadLevel ("Lobby");
     
     lobbySpawn();
 }
 
 function OnConnectedToServer () {
 
     lobbySpawn();
 }
 
 function lobbySpawn(){
 
     yield WaitForSeconds(0.1);
 
     Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
 }
 
 function refreshHostList () {
 
     MasterServer.RequestHostList(gameName);
     refreshing = true;
 }

The problem lies within the first section of the GUI function, where you press the create game button, the variable is changed to true, which means the button should stop being shown. The second set of 'creating' elements should now be visible.

This only works in the Unity Editor seen here:

alt text

However, is doesn't work in the Build seen here:

alt text

I have changed the variables around, added a function to delay the change in boolean a little, I have even tried moving the create and join buttons to a different script which destroys itself and created the shown script. All tests came back with exactly the same results. There are no errors when in the Editor. It has no obvious reason as to why it shouldn't work.

editor.png (16.4 kB)
build.png (13.3 kB)
Comment
Add comment · Show 1
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
avatar image tanoshimi · Nov 07, 2013 at 04:45 PM 0
Share

Can't recreate this - the menu looks correct in editor or in build when I click on "Create Game" (under Win8 64 bit). What platform are you building to?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by zertach · Nov 07, 2013 at 10:41 PM

Normally for 2D GUI you dont need to camera. but it is a bug or soemthing else i dont know.

but i had same problem. if you deleted Camera from your scene. again create one main camera into your scene and everything will work fine.

Comment
Add comment · Show 2 · 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
avatar image 03gramat · Nov 08, 2013 at 04:26 PM 0
Share

The big problem is i;m using the cameras because you are joining a server and your player needs its own camera, I will try without cameras first though

avatar image 03gramat · Nov 09, 2013 at 04:47 PM 0
Share

Ahh, the problem was that I didn't have a camera until you joined the server, so the GUI had no camera to work on. Thanks!

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

Script work in editor but not in build 0 Answers

uGUI objects not Instantiate()ing in executable 0 Answers

GUI works flawlessly in editor, but will not show in standalone build. 1 Answer

GUI Score Overlapping 1 Answer

Why is my canvas not going away on scene load in build, but is in editor? 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