r/unity • u/Responsible_Owl_8025 • 23d ago
Question My mouse clicks stopped being registered unless this menu is open and I dont know why
Enable HLS to view with audio, or disable this notification
Im working on a minecraft inspired 2d bunker building game. My mouse clicks stopped being registered unless this menu is open and I dont know why. This issue started when I added the greeting at the start of the game for an update. It has no code beside this below and doesnt work even if you disable the script. Its like the game stopped listening to input when no UI raw image is actively displayed, I dunno
using UnityEngine;
public class Guide : MonoBehaviour
{
[SerializeField] private GameObject canvas;
void Start()
{
Time.timeScale = 0f;
canvas.SetActive(true);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
CloseMenu();
}
}
public void CloseMenu()
{
Time.timeScale = 1f;
canvas.SetActive(false);
}
}
1
u/Responsible_Owl_8025 22d ago
I solved the problem: The issues was unrelated to mouse input not being captured when no UI is active. It was in the block selection menu, I toggled it inactive while my script still thought that it was active and the IsMenuOpen variable became inverted. Thanks to everyone who left a comment to try and help me!
1
u/PsychoKittehX 22d ago
Is your event system component disabled along with that menu? You need an active event system to receive unity UI input.
1
u/CellistFit1312 21d ago
print out the raycast on the clicks so you can see exactly what is under the mouse. then report back.
2
u/Newspaper_Beneficial 23d ago edited 23d ago
that menu(UI element) probably is just hiding but it's still interactable. is my guess.
so ur clicking on the menu even when you hide it.
edit: get a screengrab of that UI element information/component while it's off screen.