Reputation: 3
I've tried everything to figure out what's wrong.
Setting: I created a pause menu for a first person character controller that just makes a canvas appear with the pause menu.
Problem: The buttons on the canvas do not detect clicks, hovers, nothing.
My CharacterController has a PauseManager component (custom script) and the pause menu with the canvas as one of it's childs.
The PauseMananger class is as follows (relevant part):
public class PauseManager : MonoBehaviour
{
public GameObject pauseMenu;
[SerializeField] KeyCode pauseKey = KeyCode.Escape; // I've tried with other keys
bool isPaused = false;
// Start is called before the first frame update
void Start()
{
pauseMenu.SetActive(isPaused);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(pauseKey))
PauseGame();
}
void PauseGame()
{
isPaused = !isPaused;
pauseMenu.SetActive(isPaused);
if (isPaused)
{
Time.timeScale = 0;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
else
{
Time.timeScale = 1;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
}
I can't think of a cause for this, I've created a main menu with a submenu (that appears when the user clicks on options) and it works perfectly. I've been debugging and searching google for hours, I have no idea why this is not working.
The problem might be due to the fact that it has a player controller? I don't kow, any ideas are apreciated.
Upvotes: 0
Views: 487
Reputation: 66
Couldn't some image be blocking raycasts for your menu? Maybe some transparent image or some object with CanvasGroup that has checked to block raycasts option.
I also faced the exact issue you are facing, when I had my UICanvas as prefab and I drag & dropped it into a new scene. No click, hover etc. events... I was going crazy until I found out that you need EventSystem inside of your scene in order to register a click, hover, etc. events. Usually, it is created automatically when you create a canvas, but when you copy the prefab as I did, it doesn't create a new EventSystem and you must create it manually.
Upvotes: 1