Input.GetAxisRaw

Hello, I’m working on a main menu for my game. After setting up the Input Manager for use with a game pad, I wrote a basic script which should allow me to navigate through the main menu. The problem is, it’s not working as I intended. When I move the control stick up or down to scroll through the menu buttons, it starts doing so very rapidly on it’s own, and I have no control whatsoever.
Here’s the script I wrote:

#pragma strict

// The menu buttons
var thePlay : GameObject;
var theTutorial : GameObject;
var theOptions : GameObject;
var theCredits : GameObject;
var theExit : GameObject;

// The position of the button in the menu
var menuPosition : int;

// The selected button
var theSelection : GameObject;

function Start ()
{
    menuPosition = 0;
    theSelection = thePlay;
    theSelection.renderer.material.color = Color.red;
}

function Update ()
{
    if (position == 0)
    {
        if (Input.GetAxisRaw ("Gamepad Y") < 0)
        {
            menuPosition = 1;
            theSelection.renderer.material.color = Color.white;
            theSelection = theTutorial;
            theSelection.renderer.material.color = Color.red;
        }
        else if (Input.GetAxisRaw ("Gamepad Y") > 0)
        {
            menuPosition = 4;
            theSelection.renderer.material.color = Color.white;
            theSelection = theExit;
            theSelection.renderer.material.color = Color.red;
        }
    }
    else if...

    //And so on for all other menu positions
    }
    Debug.Log (Input.GetAxisRaw ("Gamepad Y");
}

Where is the problem? I’ve been striving to get this script working, three days already, and still can’t figure out what’s wrong. Could someone kindly help me?

Maybe try decreasing the sensitivity by using greater / lesser values in your conditions. This will stop small movements from been used to navigate the menu.

if (Input.GetAxisRaw ("Gamepad Y") < 0.2)

I imagine it is scrolling through uncontrollably because you have no forced delay between menu movements. This is a simple but not very elegant way to do this. It will force a delay of 0.2 seconds between menu movements.

if (Input.GetAxisRaw ("Gamepad Y") < 0.2 && lastMenuMovement < Time.time - 0.2)
    {
             lastMenuMovement = Time.time;
             menuPosition = 1;
             theSelection.renderer.material.color = Color.white;
             theSelection = theTutorial;
             theSelection.renderer.material.color = Color.red;
    }

Just store the lastMenuMovement float in the class somewhere. Hope this helps…