Using xbox 360 controler with GUI question...

Hey everyone! I kinda have 2 questions here so I'll just shoot them off one at a time:

  1. How can I access the normal, hoover, and active states of a button threw script? Basically i have this GUI i scripted up and I want the 360 controler to work with the gui and i have a way to do it all threw code and basically just changing the state of the button so the user knows what button they are selecting even though they technically are not selecting anything since it will all be done in code. If there is a way to get to these states can someone post the JS line for me? Im expecting something long the lines of button.active = false (but obviously i have no idea how to access these states atm so im just throwing out an idea of what im looking for)

  2. The above way isnt my preffered way for using the controller to interact with the gui but it's the only way I was able to come up with an idea in less then 20 mins with out knowing unity very well. I just started working with GUI 1 week ago and only been in unity for about 4 months. Sooo... with that said.. is there a better way ( in JS plz) to make the controler interact with the GUI buttons? I.E. scroll threw them, select a button and change volume on a slider... perhaps scroll down in a scroller window? Thanks all!

Well, you can do it that way. I don't have an xbox and i don't develop for it but the GUI stuff is the same. The button style you can see in the inspector when viewing a GUISkin is actually a GUIStyle. Unity will use the GUIStyle from the current GUISkin by default but you can set your own style when creating the button. Just copy the original style from the skin and do your changes. Note that you can access the default skin only inside OnGUI.

var selectedTexture : Texture2D;

function OnGUI() {
    var myButtonStyle : GUIStyle = GUIStyle(GUI.skin.button);

    if ("this button is selected") {
        myButtonStyle.normal.background = selectedTexture;
    }
    if (GUILayout.Button("button text", myButtonStyle)) {
        // button pressed
    }
}

Note: `GUIStyle(GUI.skin.button)` will create a copy of the GUIStyle instead of `GUI.skin.button` which will just be a reference to the default style. If you change the default style all buttons will be affected.