I'm facing a really weird issue with the pause menu. Whenever I pause and then unpause and pause again, the buttons lose their focus. The first time I pause:
Second time I pause:
Only the first time is working as expected, all pauses after that are like the second image(no button highlighted). I couldn't figure out the reason.
Here is my code:
void Update()
{
var gamepad = Gamepad.current;
var keyboard = Keyboard.current;
if (gamepad == null && keyboard == null)
return; // No gamepad connected.
if ((gamepad != null && gamepad.startButton.wasPressedThisFrame) || (keyboard !=null && keyboard.pKey.wasPressedThisFrame))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
public void Resume()
{
player.gameObject.GetComponent<MyPlayerMovement>().enabled = true;
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
// GameObject.Find("ThePlayer").GetComponent<MyPlayerMovement>().enabled = false;
// GameObject.Find("ThePlayer").GetComponent<InteractIcons>().enabled = false;
}
private void Pause()
{
player.gameObject.GetComponent<MyPlayerMovement>().enabled = false;
pauseMenuUI.SetActive(true);
resumeBtn.Select();
Time.timeScale = 0f;
GameIsPaused = true;
// GameObject.Find("ThePlayer").GetComponent<MyPlayerMovement>().enabled = true;
// GameObject.Find("ThePlayer").GetComponent<InteractIcons>().enabled = true;
}
I tried assigning the button in the inspector to a variable and then added this variable like so resumeBtn.Select(); in Pause() but it changed nothing.
Note that when the buttons are not highlighted, they get highlighted only after I press the arrows up or down or move the gamepad's analogue stick up or down. but at first, they are not highlighted. How can I fix this?






