- Home /
Quit Game Button Not Working
I am working on a game and have created a quit game button.
if (GUILayout.Button ("Quit")) { Debug.Log("Should be quitting");
Application.Quit();
}
The button is appearing and the Debug.Log shows that it is being clicked. However, instead of quitting, the game brings up the start menu and gives an error
"NullReferenceException: Object reference not set to an instance of an object at NetworkManager.Update () [0x00067] in C:\Users\Brady\Documents\FPS\Assets\NetworkManager.cs:243"in the log pointing to this code:
players = PhotonNetwork.room.playerCount.ToString();
What is causing this problem?
Answer by tanoshimi · Jul 07, 2014 at 09:49 PM
Have you tried calling PhotonNetwork.Disconnect();
before Application.Quit();
?
don't forget to mark correct answers by clicking the checkmark
Answer by steffenwittig · Jul 07, 2014 at 09:13 PM
Did you try it out outside of the editor? Application.Quit() will be ignored if your game is running in the editor and some other script may react to your clicks.
Yes I am aware that Application.Quit() is ignored in the editor. Also I know that the button is being clicked the error is co$$anonymous$$g from and Update() function of a different script
Answer by The-W.A.T.Z.R · Jul 07, 2014 at 10:30 PM
try this one
var levelToLoad : String;
var soundhover : AudioClip;
var beep : AudioClip;
var QuitButton : boolean = false;
function OnMouseEnter(){
audio.PlayOneShot(soundhover);
}
function OnMouseUp(){
audio.PlayOneShot(beep);
yield new WaitForSeconds(0.35);
if(QuitButton){
Application.Quit();
}
else{
Application.LoadLevel(levelToLoad);
}
}
@script RequireComponent(AudioSource)
Your answer
![](https://koobas.hobune.stream/wayback/20220613153458im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUI.Box within a Collider 1 Answer
Problems with instantiation... 1 Answer
Gui text script - help 1 Answer
GUI Button sound problem, don´t work 1 Answer
Power charger script problem 2 Answers