Controlling Pause Menu with Keyboard

Hi!

I’m still working on my Top-Down-Shooter and implemented a Pause-Menu so far. The Pause Menu consists of 3 Buttons; “Resume Game”, “Exit to Main Menu” and “Exit Game”. Clicking on them works fine, each button is doing exactly what it should. Now I want the buttons to be also controllable by Keyboard, but I’m having huge problems with this. I know or I think it should work with GUI.FocusControl, but I have no clue how to use it in my code. I don’t know how to access my already existing buttons… Could someone be so kind and give me a hint please?

Thanks in advance!

Here is my Pause-Menu-script:

using UnityEngine;
using System.Collections;

public class PauseMenu : MonoBehaviour {

	public static bool IsPaused;
	public GameObject pauseMenuCanvas;


	void Start () {	
		
		pauseMenuCanvas.SetActive(false);
	}


	void Update(){

		if (Input.GetKeyDown (KeyCode.Escape)) 
		{
			if(!IsPaused)
			{
				Time.timeScale=0;	
				IsPaused = true;
								
			}
			else
			{
				Time.timeScale=1;
				IsPaused = false;
				
			}
		}

		if (IsPaused) {
			pauseMenuCanvas.SetActive(true);

		} else {
			pauseMenuCanvas.SetActive (false);
		}
		timeRemaining -= Time.deltaTime;

	}


	public void Resume()
        {

		if(!IsPaused)
                {
			Time.timeScale=0;	
			IsPaused = true;
		}
		else
		{
			Time.timeScale=1;
			IsPaused = false;
						
		}
	}
	
	public void ExitGame(){
		IsPaused = false;
		Application.Quit();

	}

}

Hi,

To Select a Button in script you have simply to use the function “Select”.

This function is attached to all selectable object like button / inputfield…
(http://docs.unity3d.com/ScriptReference/UI.Selectable.html)

For me the easiest solution is to create a list of your button in a Controller Script. When you press “escape” put the game in pause then

list[current].Select();

Then increase or decrease current when pressing “Up” and “Down” arrow

In your button you can add a little script like

private bool isActive = false;

void OnSelect(BaseEventData eventData) {
    isActive = true;
}

void Update() {
   if (Input.GetKeyDown (KeyCode.Return))
       LaunchYourFunction();
}

I hope this help…

You need to go to Edit - > project Settings → input

from there you can configure what commands your keys send. Then you can catch those commands in your input statement.

So name the spacebar “KeyboardPause” and then in your code put if(Input.GetButton (“KeyboardPause”))