Is this possible and how should I aproach this.
I made me a start menu with options menu etc. and I figured I could just do something like:
function ShowMenu()
{
if (GUI.Button( Rect ((Screen.width/3) * 2, (Screen.height/3) + 150, 100, 30), "Options"))
{
DoSomething();
}
}
So I just had to call ShowMenu() to display the popup menu, but it doesn’t work that way I guess
What I am trying to do is that when the player hits this trigger a small popup window should come up where he has to select a choice from a few buttons and it should go away again when he presses any of the buttons.
Also, would it be possible to link the buttons to any number key so players who like to be quick can just push a key
var showMenu = false;
function OnGui()
{
if(getKeyDown("esc"))
showMenu = !showMenu
if (GUI.Button( Rect ((Screen.width/3) * 2, (Screen.height/3) + 150, 100, 30), "Options"))
CloseMenu();
}
then you display the menu you want, and to close the menu wenn a button is clicked you simply create a
function CloseMenu()
{
showMenu = false;
}
I hope to understand you right.
rgds
zem
I see how the menu can be enabled/disabled and how to attach keys to it, thank you.
In case anyone else stumbles on this topic:
var showMenu = false ; // The trigger can change it to true.
function OnGui()
{
if (showMenu)
{
if (Input.GetKeyDown("1"))
// when player pushes the 1 key its the same as if the clicked on the button
{
DoSomething();
showMenu = false ;
}
if (GUI.Button( Rect (0 ,0 ,0 ,0), "1- menu option one")) // button 1
{
DoSomething() ;
showmenu = false ;
}
}
)
private var toggle : int = 1;
function Update(){
if (Input.GetKeyDown(KeyCode.Tab)){
toggle = (toggle + 1)%2;
}
}
function OnGUI(){
if (toggle == 0){
//show GUI elements
}
}
private var toggle : bool= false;
function Update(){
if (Input.GetKeyDown(KeyCode.Tab)){
toggle = !toggle;
}
}
function OnGUI(){
if (toggle){
//show GUI elements
}
}