Mouse Scroll Weapon Change

Hey there,

I am trying to make a simple weapon change in Unity3D. The best way to do this is with the mouse Scroll wheel as far as i can see.

I googled on how to do this and found that i have to use the Input.GetAxis("Mouse ScrollWheel"); I use this piece of code and print it. Still i always get an value of 0. any ideas? I just need to solve how to get the value first, ill figure out the rest myself.

Code idea:

 function Update () {
print(WeaponNumber);

if(Input.GetAxis("Mouse ScrollWheel")){
    WeaponNumber += Input.GetAxis("Mouse ScrollWheel");
}

}

Thanks for the fast answers guys. after a bit more fooling around with the script i got it to work. tought id just post it for anyone else who might need it:

//variables

var Weapons : GameObject[];

var CurrentWeapon : GameObject;

var WeaponNumber = 0;

function Start () {

//Set Current weapon to 0
CurrentWeapon = Weapons[0];

}

function Update () {

//Get Input From The Mouse Wheel
// if mouse wheel gives a positive value add 1 to WeaponNumber
// if it gives a negative value decrease WeaponNumber with 1
if(Input.GetAxis("Mouse ScrollWheel")){
    if(Input.GetAxis("Mouse ScrollWheel") > 0){
        WeaponNumber = (WeaponNumber + 1);
    }
    if(Input.GetAxis("Mouse ScrollWheel") < 0){
        WeaponNumber = (WeaponNumber - 1);
    }   
}
CurrentWeapon = Weapons[WeaponNumber];

}

Instead of Input.GetAxis you may use Input.GetAxisRaw. The value for GetAxis is smoothed and is in range -1 .. 1 , however GetAxisRaw is -1 or 0 or 1. and you may remove the If statement. cause when no scrollwheel happens the value is automatically zero.

http://forum.unity3d.com/threads/6753-getting-input-from-quot-Mouse-ScrollWheel-quot?p=161834

var Weapons : GameObject;

var CurrentWeapon : GameObject;

var WeaponNumber = 0;

function Start () {

    //Set Current weapon to 0
    CurrentWeapon = Weapons[0];

}

function Update () {

    //Get Input From The Mouse Wheel
    // if mouse wheel gives a positive value add 1 to WeaponNumber
    // if it gives a negative value decrease WeaponNumber with 1
    if(Input.GetAxis("Mouse ScrollWheel")){
        if(Input.GetAxis("Mouse ScrollWheel") > 0){
            WeaponNumber = (WeaponNumber + 1);
        }
        if(Input.GetAxis("Mouse ScrollWheel") < 0){
            WeaponNumber = (WeaponNumber - 1);
        }   
    }
    CurrentWeapon = Weapons[WeaponNumber];

}

:slight_smile: