Strange problem with GUI and input

I am trying to make a control panel sort of feature using Unity3d’s GUI class and i have a strange problem.

As shown in the code above, you can either press the GUI button or press a key. When you press the button everything works, it toggles priEnabled and plays a sound but when you press the keep it only plays the beep. Now, i have the same sort of thing again for different buttons as shown below.

if (GUI.Button(new Rect(boxPos.x + spacing.x, boxPos.y + spacing.y, buttonSize.x, buttonSize.y), "Front \nBlues") || Input.GetKeyUp(KeyCode.Keypad7))
{
    priEnabled = !priEnabled;
    audio.PlayOneShot(beepSound);
}
if (GUI.Button(new Rect(boxPos.x + spacing.x, boxPos.y + spacing.y * 2, buttonSize.x, buttonSize.y), "Rear \nBlues") || Input.GetKeyUp(KeyCode.Keypad4))
{
    audio.PlayOneShot(beepSound);
}
if (GUI.Button(new Rect(boxPos.x + spacing.x * 2, boxPos.y + spacing.y, buttonSize.x, buttonSize.y), "Headlights \nFlash") || Input.GetKeyUp(KeyCode.Keypad8))
{
    audio.PlayOneShot(beepSound);
    hlEnabled = !hlEnabled;
}
if (GUI.Button(new Rect(boxPos.x + spacing.x * 2, boxPos.y + spacing.y * 2, buttonSize.x, buttonSize.y), "Rear \nReds") || Input.GetKeyUp(KeyCode.Keypad5))
 {
    audio.PlayOneShot(beepSound);
    secEnabled = !secEnabled;
}
if (GUI.Button(new Rect(boxPos.x + spacing.x * 3, boxPos.y + spacing.y, buttonSize.x, buttonSize.y), "Siren") || Input.GetKeyUp(KeyCode.Keypad9))
{
    audio.PlayOneShot(beepSound);
    sirenEnabled = !sirenEnabled;
}
if (GUI.Button(new Rect(boxPos.x + spacing.x * 3, boxPos.y + spacing.y * 2, buttonSize.x, buttonSize.y), "Arrival") || Input.GetKeyUp(KeyCode.Keypad6))
{
    audio.PlayOneShot(beepSound);
    priEnabled = true;
    secEnabled = true;
    hlEnabled = false;
    sirenEnabled = false;
}

the last button works when i press the button or press the key which is good but the rest of them don’t. i thought maybe it could be the way i’m setting the boolean variable.

priEnabled = !priEnabled;

but its not that because even when i changed it to the code below, it still didnt toggle whe ni pressed the key, only when i pressed the GUI button.

if(priEnabled)
    priEnabled = false;
else
    priEnabled = true;

The problem cant be anywhere else in the script because everything works when pressing the buttons but not when im pressing the keys. I’ve also tried using the Input.GetButtonDown() function with all the appropriate values setup in the editor but even that doesn’t work. I’m thinking this could be a possible bug in the Unity3d compiler, but im not sure.

Please can somebody help, Thanks in advance.

Inputs shouldnt be done in the OnGUI(), but instead in the Update(). Also, you are using GetKey, meaning no matter if you press, hold or release, the beepSound will play a bazilion times. use GetKeyDown, so sound plays only when u press the key instead of holding it.

if(priEnabled)

    priEnabled = false;

else

    priEnabled = true;

why u do dis? it will set it to false if its true, or it will set to true if its false. you shouldnt do that

I changed the inputs to the update function and it works. Thanks ! that was stupid of me wasn’t it.