- Home /
Unity3d build project gui
I have a menu with a gui button, a gui label and a text field. When I click the button, the button, the label and the text field should be disabled and disappear. It works in the editor, but when I build the game, it just keeps showing until I spawn my player.
Comment
using UnityEngine;
using System.Collections;
public class $$anonymous$$enu_$$anonymous$$anager : $$anonymous$$onoBehaviour {
//BOOLEANS
bool menuGUI = true;
bool serverGUI = false;
//FLOATS
public float respawnTimer = 0;
//STRINGS
string Username;
// Use this for initialization
void Start () {
Username = PlayerPrefs.GetString ("Username");
}
void OnDestroy(){
PlayerPrefs.SetString ("Username", Username);
}
// Update is called once per frame
void Update () {
if(respawnTimer > 0){
respawnTimer -= Time.deltaTime;
}
if(respawnTimer < 0){
respawnTimer = 0;
SpawnPlayer();
}
}
void OnGUI(){
if(menuGUI){
GUI.Label (new Rect (0, 0, 100, 20), "Username:");
Username = GUI.TextField (new Rect (65, 0, 125, 20), Username, 16);
if(GUI.Button(new Rect(65,40,100,20), "$$anonymous$$ultiplayer")){
menuGUI = false;
//Connect ();
serverGUI = true;
}
}
if(serverGUI){
if(GUI.Button (new Rect(65,40,150,20), "Join Random Server")){
Connect ();
serverGUI = false;
}
}
}
void Connect(){
PhotonNetwork.ConnectUsingSettings ("Alpha Version 0.1");
}
void OnJoinedLobby(){
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed(){
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom(){
SpawnPlayer ();
}
void SpawnPlayer(){
PhotonNetwork.player.name = Username;
Screen.lockCursor = true;
GameObject Player = (GameObject)PhotonNetwork.Instantiate ("Character", Vector3.zero, Quaternion.identity, 0);
Player.GetComponent<$$anonymous$$ouseLook> ().enabled = true;
Player.GetComponent<Character$$anonymous$$otor> ().enabled = true;
Player.GetComponent<FPSInputController> ().enabled = true;
Player.transform.Find ("$$anonymous$$ain Camera").GetComponent<$$anonymous$$ouseLook> ().enabled = true;
Player.transform.Find ("$$anonymous$$ain Camera").camera.enabled = true;
}
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Game Object enable for game mode selection on GUI 1 Answer
Weapon Selection Script 1 Answer
[CLOSED]RaycastAll Help 1 Answer
GUI Resolution Ajust 1 Answer