- Home /
Controlling pause menu with keyboard in Unity 4.6?
I've done some quick googling and it seems that Unity doesn't natively support keyboard menu controls. However, most of the threads I found were before the current GUI update. I was wondering how you'd go about implementing a keyboard-controlled pause menu in 4.6 given the way that UI objects currently work.
Answer by Kiwasi · Dec 01, 2014 at 08:30 AM
Step 1 - Make a pause menu
Step 2 - Press play
Keyboard navigation is supported by default on the new UI. While there are plenty of ways to customise it, you don't actually need to do anything for it to work.
...lol. Thanks. Can't believe I didn't realize that.
So I got it working, but for some reason keyboard controls don't work by default when I open my pause menu. I have to click on a button with my mouse before they become selectable by keyboard.
This sounds like a focus problem, but how do I set focus to a window in 4.6? I found this method but it looks like the legacy system http://docs.unity3d.com/ScriptReference/GUI.FocusWindow.html
All you need to use is this! I had the same problem before - found the solution here somewhere. :) Just rename the -$$anonymous$$ain- to your game object!
-$$anonymous$$ain- = GameObject.Find ("-$$anonymous$$ain-").transform;
EventSystem eventSystem = GameObject.Find("EventSystem").GetComponent<EventSystem>();
eventSystem.SetSelectedGameObject(_-$$anonymous$$ain-_.gameObject, new BaseEventData(eventSystem));