- Home /
Unable to click UI Button (Unity 4.6) when TimeScale is 0
I'm developing a game and I'm currently creating the pause menu. Whenever I press the key for pause the game (p in my case) it stops just as I want setting Time.timeScale to 0. After it I want to show the buttons for resuming the game, go back to main menu, quit it, etc. but then I'm unable to click them.
I have some testing only buttons using the old GUI features and they still work when the game is paused but I can't click the Unity 4.6 UI buttons.
When I test this, Unity UI buttons work, even when Time.timeScale is 0.
Are you sure it's not some animations that are not playing?
If so, go to your Animator component and in the inspector and change the 'Update $$anonymous$$ode' to 'Unscaled Time'...
For a better explanation, I have a Button with a disabled $$anonymous$$i script attached. This script is only this:
public class ResumeGame : $$anonymous$$onoBehaviour{
void Start (){
Gamestate.instance.gameObject.GetComponent<Pause>().unpause();
this.enabled = false;
}
}
In the same button's OnClick() function I enable this script, so when I click the button it should enable this script, resume the game and then disable it.
The problem comes when I can't click it. I've done this method in the main menu and it works, so the only thing co$$anonymous$$g to my $$anonymous$$d is the timeScale set to 0.
Answer by esandez93 · Jan 30, 2015 at 03:38 AM
I've found the solution! The Button is attached to a Canvas that is attached to a GameObject that DontDestroyOnLoad(). But this 4.6 Unity UI needs an EventSystem GameObject which is created when you create the Canvas, but as my Canvas was created in a previous scene, in my current scene (where I wanted to click the Button) I wasn't able to click it.
Tl;dr: If you have an UI Button you need an EventSystem in the scene.
I hope someone find it useful!
Thank you very much for posting your reply! It's the only resource that allow me to fix this bug! Thank you again!!!