Forum begins after the advertisement:
[part 11] UI buttons dont work
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [part 11] UI buttons dont work
- This topic has 5 replies, 2 voices, and was last updated 1 week, 1 day ago by Terence.
-
AuthorPosts
-
December 9, 2024 at 8:39 pm #16708::
so i just finished part 11 and everything works perfecty fine except now the UI buttons on the pause menu dont work. if i click “resume”, the pause menu will dissapear but the scene will be frozen still. and if i click quit to main menu, nothing happens.
this isnt a code bug i think since the game pauses and unpauses if i click the “escape” key. ive checked a few times and both buttons seemed to be configured correctly?
View post on imgur.com
private void Update() { if (Input.GetKeyDown(KeyCode.P)) { SaveData.Instance.SavePlayerData(); } if (Input.GetKeyDown(KeyCode.Escape)) { Pause(!isPaused); } } public void Pause(bool b) { if (b) { if (lastTimeScale < 0) lastTimeScale = Time.timeScale; Time.timeScale = 0; } else { if (!isStopped) { Time.timeScale = lastTimeScale; lastTimeScale = -1; } } pauseMenu.Fade(fadeTime, b); isPaused = b; } public static void Stop(float duration = 0.5f, float restoreDelay = 0.1f, float slowMultiplier = 0f) { if (stopGameCoroutine != null) return; stopGameCoroutine = Instance.StartCoroutine(HandleStopGame(duration, restoreDelay, slowMultiplier)); } static IEnumerator HandleStopGame(float duration, float restoreDelay, float slowMultiplier = 0f) { if(Instance.lastTimeScale < 0) Instance.lastTimeScale = Time.timeScale; Time.timeScale = Instance.lastTimeScale * slowMultiplier; WaitForEndOfFrame w = new WaitForEndOfFrame(); while(duration > 0) { if (Instance.isPaused) { yield return w; continue; } Time.timeScale = Instance.lastTimeScale * slowMultiplier; duration -= Time.unscaledDeltaTime; yield return w; } float timeScaleToRestore = Instance.lastTimeScale; Instance.lastTimeScale = -1; stopGameCoroutine = null; if(restoreDelay > 0) { float currentTimeScale = timeScaleToRestore * slowMultiplier; float restoreSpeed = (timeScaleToRestore - currentTimeScale) / restoreDelay; while(currentTimeScale < timeScaleToRestore) { if (Instance.isPaused) { yield return w; continue; } if (isStopped) yield break; currentTimeScale += restoreSpeed * Time.unscaledDeltaTime; Time.timeScale = currentTimeScale; yield return w; } } if (!isStopped) Time.timeScale = timeScaleToRestore; }
December 10, 2024 at 12:49 am #16711::Make sure that the Canvas Group on the Pause Screen has both Interactable and Blocks Raycasts checked. If you added a UI Screen without adding a Canvas Group, the Canvas Group that is automatically added will not have both checked.
December 11, 2024 at 1:58 am #16726December 11, 2024 at 11:15 pm #16741::Is another UI element blocking your Pause buttons? Try deleting everything in your Canvas temporarily, then running the game to see if you can click on the buttons on the Pause screen.
You may find this short helpful as well:
December 13, 2024 at 1:15 am #16748::Oh no. The buttons are interactiable since when I click on them, the pause screen will disappear but the functions of sending me to the main menu or unpausing the game won’t work until I click the escape key after unpausing. I think the functions are being affected by the time stop?
December 13, 2024 at 6:41 pm #16757 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: