Enabling the use of arrow keys for a menu while in FPS controller

Hello to all,

I have been toying around with unity for about a month now. I have found only one reference of this topic.

Here is what i am trying to do:

While in FPS Controller, when i press the “c” key, a menu pops up to rotate a cannon i have on my building. When the menu pops up i want to be able to use the up and down arrow keys to scroll threw the buttons on the menu.

The issue i am having is that when i bring up the menu, i cant get the arrow keys to work because they are making me move to the forward and backward due to the FPS controller.

The reason i want to do this is because i currently have my cursor locked to the center of the screen with a cross hair in the center of the GUI, so i cant use it to hover over buttons.

Here is the JavaScript i have so far for this:

#pragma strict

function Update()
{
	
}

function OnGUI  () 
{
    GUI.contentColor = Color.white;

    if (GUI.RepeatButton (Rect (600, 300, 200, 100), "Rotate Right"))
	{
		// Rotate Right
	}
	
	if (GUI.RepeatButton (Rect (600, 450, 200, 100), "Rotate Left"))
	{

   		// Rotate Left
	}
	
	// Use arrow keys to sellect buttons
	
	if (Input.GetButton("down")) 
   	{
        GUI.FocusControl("Rotate Right");
    }
    if (Input.GetButton("up")) 
    {
       	GUI.FocusControl("Rotate Left");
    }
}

I was following this idea someone had and trying to get it to work for Java. Here is a link to that page: GUI Button keyboard? - Questions & Answers - Unity Discussions

From what I understood, you want to toggle the menu on and off with the key C, and need the character stopped when the menu is on the screen. You could toggle a variable showMenu to control the menu, and assign its complement to the variable canControl inside the script CharacterMotor.js, like this:

#pragma strict

var charMotor: CharacterMotor;
var showMenu: boolean = false;

function Update()
{
  if (!charMotor){ // get reference to the CharacterMotor script:
    charMotor = GameObject.FindWithTag("Player").GetComponent(CharacterMotor);
  }
  if (Input.GetKeyDown("c")){ // toggle menu on/off with C
    showMenu = !showMenu; // toggle showMenu
    charMotor.canControl = !showMenu; // disable character control when menu appears
  }
}

function OnGUI  () 
{
    if (showMenu){
        GUI.contentColor = Color.white;
        if (GUI.RepeatButton (Rect (600, 300, 200, 100), "Rotate Right"))
	{
		// Rotate Right
	}
	
	if (GUI.RepeatButton (Rect (600, 450, 200, 100), "Rotate Left"))
	{
   		// Rotate Left
	}
	
	// Use arrow keys to sellect buttons
	
	if (Input.GetButton("down")) 
   	{
            GUI.FocusControl("Rotate Right");
        }
        if (Input.GetButton("up")) 
        {
       	    GUI.FocusControl("Rotate Left");
        }
    }
}

Awesome, ill give it a try.

Tried it and that did not work this is the code i have:

#pragma strict

public var Cannon : GameObject;
var charMotor: CharacterMotor;
var showMenu: boolean = false;

var speed: float = 60; // speed in degrees per second

function Update()
{
if (!charMotor)
{
// Get reference to the CharacterMotor script
charMotor = GameObject.FindWithTag(“Player”).GetComponent(CharacterMotor);
}

if(Input.GetKeyDown("c"))
{
	showMenu = !showMenu;				// Toggle the Menu
	charMotor.canControl = !showMenu;	// Disable the character control when menu is up
}

}

function OnGUI ()
{
GUI.contentColor = Color.white;

if (GUI.RepeatButton (Rect (200, 300, 200, 100), "Rotate Right"))
{
	// Rotate Right
	//gameObject.rigidbody.rotation.y + 1;
	gameObject.rigidbody.transform.Rotate(0, -speed*Time.deltaTime, 0);
}

if (GUI.RepeatButton (Rect (200, 450, 200, 100), "Rotate Left"))
{
	// Rotate Left
	gameObject.rigidbody.transform.Rotate(0, -speed*Time.deltaTime, 0);
	
}

// Use arrow keys to sellect buttons

if (Input.GetButton("Down")) 
{
    GUI.FocusControl("Rotate Right");
}
if (Input.GetButton("Up")) 
{
   	GUI.FocusControl("Rotate Left");
}

}