- Home /
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
}
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.
Sadly that didnt solve the problom bu thanks for the advice
is there an option for it to be a bug in unity?
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
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613172201im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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