UI buttons not detecting mouse click/mouseover
So I've implemented a pause menu following some tutorials, however the menu seems to be completely unable to detect the mouse at all, including left click.
What's 'meant' to happen is the buttons darken when hovered over, and then darken moreso when clicked on, however they just always appear dark, and nothing happens when they're clicked on.
Looking at other people with this issue I have double checked I have an Event System, and that everything's on one canvas.
I've attached some screenshots that'll hopefully help out.
Note a lot of the stuff on the UI is a fellow Student's work, so forgive the lack of organisation, I've tried disabling his components and it still doesn't work sadly.
Here's the code for the pause menu:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PauseMenu : MonoBehaviour
{
public static bool gameIsPaused = false;
public GameObject pauseMenuUI;
CursorLockMode desiredMode;
void Update () {
if (Input.GetKeyDown(KeyCode.Escape))
{
if (gameIsPaused)
Resume();
else
Pause();
}
}
public void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
gameIsPaused = false;
Cursor.visible = false;
desiredMode = CursorLockMode.Confined;
}
void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
gameIsPaused = true;
Cursor.visible = true;
desiredMode = CursorLockMode.None;
}
public void Quit()
{
Debug.LogWarning("Game quits if not in Unity editor");
Application.Quit();
}
}
Answer by Vicarian · May 11, 2018 at 02:55 PM
On your Canvas Group component, Interactable is disabled. Check that to enable it and events should process.
@Vicarian Thanks! That fixed the first issue, but now back with a new one.
So in some magical twisted turn of events, now when I -click- the resume button ins$$anonymous$$d of pressing escape to resume, the camera detaches itself from the player.
Pausing and unpausing again using escape seems to fix said issue, but whenever I resume with a left click the camera dies.
EDIT:
So the issue is that I was disabling the camera rotation when the game was paused. As this is done in the camera script and not the pause menu script like the rest of the code was, I was stupidly making a second bool in the Camera orbit script, with it switching states on the press of the escape button.
I'll fix this by having it switch depending on what gametime is. As when the game pauses gametime goes to 0f.
You assign CursorLock$$anonymous$$ode to a var, but you don't actually set it:
Cursor.lockState = desired$$anonymous$$ode;
Ah yeah, I was planning to lock the cursor to the screen while the game is playing, but forgot to properly test it and moved onto other things. Thanks once more! :)
Exactly! For me I also needed to check "Block raycast" for it to work
Your answer
Follow this Question
Related Questions
C# Pause Menu Buttons not working in only 1 scene 1 Answer
Getting BCE0005: Unknown identifier: 'EditorStyles' error what is wrong with this piece of code? 0 Answers
How to make a button control Animator animation 0 Answers
unity UI button is not behaving correctly in build 0 Answers
Swap 3D model with a button 2 Answers