- Home /
Exit button stopped working
I originally had an exit button set up just for show, and when clicked it would call a function that would write "Game exited" to the console. However, after adding the code that will actually make the game go through my end game sequence, the button no longer works. It's like I can't click it anymore. I tried to have it write to the console again, but nothing happened. I have the information in the inspector set up so that the On Click() option is: Runtime only, on the ExitButton script, and the function used it ExitButton.ExitTheGame. This is my code for the ExitButton script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExitButton : MonoBehaviour {
public GameOverManager gom;
public void ExitTheGame(){
Debug.Log ("Exit Button pushed");
gom.SetBoolGO ();
}
}
This calls a function in the GameOverManager that will set a boolean value to true, which tells that script to activate the GameOver Screen and exit. I don't know what I did wrong, but it wont work any more. If anyone thinks that they can help me, I could really use some guidance.
-Thanks!
Do you still have an event system in the scene? Is the button graphic marked as raycast target?
Yes, it is. And, I actually just figured out what was wrong. I had added a flash image that stretches across the screen that will flash red whenever the player is hurt (very similar to the survival shooter tutorial, if you know of it), and my exit button was under this image. I did not realize this because the alpha for the image had been turned to zero until the player is hurt. Once I moved the button to on top of this image, the button worked again.
Just a note: you could also turn off raycast target on the red flash. You should add your solution as an answer so others see it as answered.
Answer by $$anonymous$$ · Dec 12, 2017 at 08:32 AM
For anyone who is having this issue I found the solution:
I had added a flash image that stretches across the screen that will flash red whenever the player is hurt (very similar to the survival shooter tutorial, if you know of it), and my exit button was under this image. I did not realize this because the alpha for the image had been turned to zero until the player is hurt. Once I moved the button to on top of this image, the button worked again.
Your answer
Follow this Question
Related Questions
Button doesn't work after build 1 Answer
Make a button quit the game, Unity 4.6 UI C# 1 Answer
Menu button in game isn't working 0 Answers
Unity 5.0.2f1 UI Button OnClick Function 6 Answers
Make a UI button quit the exe, Unity 5 2 Answers