- Home /
Question by
Sondre-S · Apr 29, 2015 at 01:35 PM ·
buttonkeypresscontinuous
Avoid continous GetButton on menu
This is supposed to not detect continously, to avoid looping through the menu. Works for the key press, but not for the button.
// Cancel
if((Input.GetKeyDown(KeyCode.Backspace) || Input.GetButton("Fire1")) ){
GoBack= true;
audio.PlayOneShot(cancelSound,MenuVolume);
}
else
{
GoBack= false;
}
I even tried with a bool to detect if the key/button is held down:
// Cancel
if((Input.GetKeyDown(KeyCode.Backspace) || Input.GetButton("Fire1")) && cancelKey){
GoBack= true;
audio.PlayOneShot(cancelSound,MenuVolume);
cancelKey=false;
}
if(!(Input.GetKeyDown(KeyCode.Backspace) && Input.GetButton("Fire1")) && !cancelKey){
GoBack= false;
cancelKey=true;
}
But that didnt work either.........
Comment
Best Answer
Answer by Sondre-S · Apr 29, 2015 at 01:43 PM
Never mind found a working solution:
// Cancel choice
if((Input.GetKeyDown(KeyCode.Backspace) || Input.GetButton("Fire1")) && !cancelKey){
GoBack= true;
audio.PlayOneShot(confirm,MenuVolume);
if(Menu!="MainMenu"){ // reset bar position when cancel if not on main menu
MenuPosition=1;
}
cancelKey=true;
}
else
{
GoBack= false;
}
if(cancelKey&&(!Input.GetKeyDown(KeyCode.Backspace) && !Input.GetButton("Fire1"))){
cancelKey=false;
}