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 stridernara · Nov 22, 2014 at 04:48 PM · guibuildgui-button

GUI messed up after build

When I'm in the editor the GUI is okey and works fine after I build I get the main menu and I click on play for example clicking on play should pass me to the hero select screen and close the main menu screen all it does is just showing the hero screen but wont close the main menu then I click back so It should close the hero select and open the mainmenu but it wont he just stays open but in active I think that the picture dont change but by code it wont exist Here is my mainmenu code:

 using UnityEngine;
 using System.Collections;
 
 public class MainMenu : MonoBehaviour
 {
     private bool inMenu;
     private bool heroSelect;
     private bool mpHeroSelect;
     private bool serverSelect;
     private bool optionScreen;
 
     //slots
     public GameObject heroOne;
     public GameObject heroTwo;
     public GameObject heroThree;
 
     public bool heroOneChosen;
     public bool heroTwoChosen;
     public bool heroThreeChosen;
 
     public GameObject spawnPoint;
 
 
     // Use this for initialization
     void Start () 
     {
         inMenu = true;
         spawnPoint = GameObject.FindGameObjectWithTag ("Spawn Point");
     }
 
     void OnGUI()
     {
         if(inMenu)
         {
             DrawMainMenu ();
         }
 
         if(heroSelect)
         {
             DrawHeroSelect ();
         }
 
         if (mpHeroSelect)
         {
             DrawMPHeroSelect ();
         }
 
         if(serverSelect)
         {
             DrawServerSelect ();
         }
 
         if(optionScreen)
         {
 
         }
     }
 
     void DrawMainMenu ()
     {
         if (GUI.Button (new Rect(Screen.width / 2 - 100,Screen.height / 2 - 75, 200, 50), "Play Singleplayer"))
         {
             heroSelect = true;
             inMenu = false;
         }
 
         if (GUI.Button (new Rect(Screen.width / 2 - 100,Screen.height / 2 - 25, 200, 50), "Play Multiplayer"))
         {
             mpHeroSelect = true;
             inMenu = false;
         }
 
         if (GUI.Button (new Rect(Screen.width / 2 - 100,Screen.height / 2 + 25 , 200, 50), "Options"))
         {
 
         }
 
         if (GUI.Button (new Rect(Screen.width / 2 - 100,Screen.height / 2 + 75, 200, 50), "Exit"))
         {
             Application.Quit ();
         }
     }
 
     void DrawHeroSelect ()
     {
         if(GUI.Button(new Rect(Screen.width - 200, Screen.height - 50, 200,50),"Play!"))
         {
             heroSelect = false;
             SpawnPlayer(0);
         }
 
         if(GUI.Button(new Rect(0, Screen.height - 50, 200,50),"Back"))
         {
             heroSelect = false;
             inMenu = true;
         }
 
         //slots
         if(GUI.Button(new Rect(10,10,180,50),heroOne.name))
         {
 
         }
 
         if(GUI.Button(new Rect(10,70,180,50),heroOne.name))
         {
             
         }
 
         if(GUI.Button(new Rect(10,130,180,50),heroOne.name))
         {
             
         }
     }
 
     void DrawMPHeroSelect ()
     {
         if(GUI.Button(new Rect(Screen.width - 200, Screen.height - 50, 200,50),"Play!"))
         {
             serverSelect = true;
             mpHeroSelect = false;
         }
         
         if(GUI.Button(new Rect(0, Screen.height - 50, 200,50),"Back"))
         {
             heroSelect = false;
             inMenu = true;
         }
         
         //slots
         if(GUI.Button(new Rect(10,10,180,50),heroOne.name))
         {
             
         }
         
         if(GUI.Button(new Rect(10,70,180,50),heroOne.name))
         {
             
         }
         
         if(GUI.Button(new Rect(10,130,180,50),heroOne.name))
         {
             
         }
     }
 
     //Server
 
     void DrawServerSelect ()
     {
         if (!Network.isClient && !Network.isServer)
         {
             if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
                 StartServer();
             
             if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh Hosts"))
                 RefreshHostList();
             
             if (hostList != null)
             {
                 for (int i = 0; i < hostList.Length; i++)
                 {
                     if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList[i].gameName))
                         JoinServer(hostList[i]);
                 }
             }
         }
     }
 
     private const string typeName = "Rpg";
     private const string gameName = "Sean";
     
     
     private void StartServer()
     {
         Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
         MasterServer.RegisterHost(typeName, gameName);
     }
 
     private HostData[] hostList;
     
     private void RefreshHostList()
     {
         MasterServer.RequestHostList(typeName);
     }
     
     void OnMasterServerEvent(MasterServerEvent msEvent)
     {
         if (msEvent == MasterServerEvent.HostListReceived)
             hostList = MasterServer.PollHostList();
     }
     
     private void JoinServer(HostData hostData)
     {
         Network.Connect(hostData);
     }
     
     public GameObject playerPrefab;
     
     void OnServerInitialized()
     {
         SpawnPlayer(1);
     }
     
     void OnConnectedToServer()
     {
         SpawnPlayer(1);
     }
     
     private void SpawnPlayer(int accses)
     {
         if(accses == 1)
         {
             Network.Instantiate(playerPrefab,spawnPoint.transform.position, Quaternion.identity, 0);
         }
         if(accses == 0)
         {
             Instantiate(playerPrefab, spawnPoint.transform.position, Quaternion.identity);
         }
     }
     //Server end    
 }
Comment
Add comment · Show 4
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 RadioactiveTechnologies · Nov 22, 2014 at 05:12 PM 0
Share

That code is inefficient. Ins$$anonymous$$d of using all those functions being spawned from the OnGUI, you could just put those in the if statements. I know that isn't the answer you're looking for. But that would be more efficient and may fix the problem.

avatar image stridernara · Nov 22, 2014 at 05:49 PM 0
Share

Sadly that didnt solve the problom bu thanks for the advice

is there an option for it to be a bug in unity?

avatar image RadioactiveTechnologies · Nov 22, 2014 at 06:05 PM 0
Share

I don't believe there is any known bugs with Unity GUI. I believe that there is a bug in the code. It;s just so long with so little actual outcome that I can't really bother to find out where. At least you use C#. I can't stand Javascript :P

avatar image stridernara · Nov 23, 2014 at 06:02 AM 0
Share

I'll check this code today once agien with my $$anonymous$$d clear but the idea is that in teh editor everthing is fine but after I build it's getting messed up

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

GUI not work after building 1 Answer

Enable and disable a button selection 3 Answers

GUI Button screen Width and Centering Problem 4 Answers

Why is my code duplicating the name of a button? styling gui 1 Answer


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