Xbox controller not working in OnGUI but, otherwise it does?

Hi.

I am using a 360 controller to control my game and it works well but, I noticed that the controller dose not respond to code inside the OnGUI function. How can this be? My controller works fine outside OnGUI(tested with prints) but, as soon as I access the OnGUI function the controller wont respond to something like :

  function OnGUI (){
     if(Input.GetButtonDown("XButton")){
     print("Moving")
     }
    }

Yes the Input buttons are setup correctly as said the controller responds fine from Update, LateUpdate, FixedUpdate… I just dont get why it wont respond in OnGUI when it responds in all the other functions.

Can you please help me? Since my game is a GUI-heavy game it is really a setback not to be able too use my 360 controller.

Or is this a limitation of Unity? That you cannot use a 360 controller in a GUI function?

Thank you.

OnGUI gets called several times per frame, so input doesnt work. Use event.current instead. I’d post a link to the docs but im on my phone :wink:

2 Possible ideas. 1)Try taking the input variable outside say into a function Update() and use the gui highlight or when over with cursor allow the input to be done. 2) Make a Script souly for the Guis with a cycling for when its this certain number change texture and when over that number and certain button hit goto place - Example:

var numberOfOptions = 3;
var currentNumber = 1;
var gui1: Transform;
var gui2: Transform;
var gui3: Transform;
var highlightTexture: Texture;
var normalTexture: Texture;
private var texture1;
private var texture2;
private var texture3;
function Update()
{
  texture1 = gui1.GetComponent(GUITexture).Texture;
  texture2 = gui2.GetComponent(GUITexture).Texture;
  texture3 = gui3.GetComponent(GUITexture).Texture;
 if(Input.GetButtonDown("UpKey"))
 { private var stop = 0;
    if(currentNumber == numberOfOptions)
    {
     stop = 1;
     currentNumber = 1;
    }
    if(currentNumber < numberOfOptions)
     {     
     if(stop == 0)
     {
     currentNumber = currentNumber + 1;
     }
     stop = 0;
  }
 }
 if(Input.GetButtonDown("DownKey"))
 { private var stop = 0;
    if(currentNumber == 1 )
    {
     stop = 1;
     currentNumber = numberOfOptions;
    }
    if(currentNumber > 1)
     {     
     if(stop == 0)
     {
     currentNumber = currentNumber - 1;
     }
     stop = 0;
     }
 }
 if(currentNumber == 1)
  {
    texture1 = highlightTexture;
    if(Input.GetButtonDown("XButton"))
    {
      //goto code
    }

  }
  else
  {
     texture1 = normalTexture;
  }
   if(currentNumber == 2)
  {
    texture2 = highlightTexture;
    if(Input.GetButtonDown("XButton"))
    {
      //goto code
    }

  }
  else
  {
     texture2 = normalTexture;
  }
   if(currentNumber == 3)
  {
    texture3 = highlightTexture;
    if(Input.GetButtonDown("XButton"))
    {
      //goto code
    }

  }
  else
  {
     texture3 = normalTexture;
  }
}

Its not on GUI but its simulating it it is good for console only. sorry if i wasn't a help. Glad if I did help.