Quit button not working?

Preface, I have absolutely no programming experience so ELI5
And yes I’ve built the game, run the exe and the button does not work there.
It appears like it’s working, the colours change when mousing over and clicking but when it is clicked- nothing happens.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseMenu : MonoBehaviour
{

    public void QuitGame()
    {

        Application.Quit();

    }

}

This is what my script looks like. I attached it to a GameObject in my scene, and then attached that object to the on click event for the button.
7046917--835723--upload_2021-4-16_11-17-1.png

I’ve been trying to google search an answer for a couple of hours now but I can’t get anything to work.

Edit: I tried adding a debug log and, if I’m looking in the correct place and doing this correctly, it doesn’t fire off when I click the button

Hello,

If you put a Debug.Log in your quit game function, does it register?

It doesn’t seem to if I’m doing it right. I play in the editor, hit the button, check the console, and there is no debug message there.

your script appears to work, when I put it on a game object and attached it to the on click event it worked fine. so it’s not the script.

question:

  1. what game object is the script on and what is the game object doing?

It’s just a low poly vehicle placed in the scene. It doesn’t have a purpose or any other components attached to it.

As a matter of style, it’s best to centralize UI responder scripts, either to the root Canvas they belong under, or another GameObject where they can all live. Otherwise you will hate yourself trying to find them later.

Also, Application.Quit() does NOTHING in the Unity editor.

And also +1 to Magnesium’s post above. We know buttons didn’t stop working, so review what you need:

  • EventSystem
  • no “RaycastTarget” objects in front of the button
  • button must have a “Graphic” with RaycastTarget enabled
  • valid hookup of delegate (your image above)
  • etc.

We know it works.

1 Like