I’m new to Unity and I’ve been trying to make a quit button for my game. I attached a script called “Quit” to a button. In the “On Click” section, I put my button object in and set the function to “Quit.QuitGame”. For some reason, the button does nothing. It doesn’t even change colour when hovered on. Yes, interactable is on. The “Quit” script looks like this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Quit : MonoBehaviour
{
public void QuitGame()
{
Application.Quit();
}
}
I just noticed you said it doesn’t change color when hovering. If other buttons work, check that there isn’t something on top of the one not working. In builds the aspect ratio might be different, so the on top issue doesn’t happen. To test you can play with the editor Game tab ratio here:
If no buttons work, you might be missing an EventSystem in the scene, usually one is generated when you create any canvas in-scene. I think this is less likely though since you said it worked in build.
Its a component called EventSystem, usually on a generated gameobject in the hierarchy called EventSystem. It has something to do with receiving events for a Canvas like mouse hover and button click.
You can easily add one if you go to a scene, right click → UI → EventSystem. As I said though it’s usually generated when you add a canvas to the scene, and wouldn’t cause an issue like this if the button works in the build.