Different MouseWheel Functionality

for those of you looking for a way to stop at the end of the list on mouse wheel down and stop at the beginning of the list on mouse wheel up… it would look something like this…

(I have a reference to what game object holds the weapons in the case the script is somewhere else that might make sense to you, but if you don’t want a reference and just want to put this script on the gameobject that is the parent of the weapons, change “weaponHolder.transform” to just “transform” like @Rick_Davidson has it)

private void ProcessScrollWheel()
    {
        MouseWheelDown();
        MouseWheelUp();
    }

    private void MouseWheelUp()
    {
        if (Input.GetAxis("Mouse ScrollWheel") < 0)
        {
            if (currentWeapon <= 0)
            {
                currentWeapon = 0;
            }
            else
            {
                currentWeapon--;
            }
        }
    }

    private void MouseWheelDown()
    {
        if (Input.GetAxis("Mouse ScrollWheel") > 0)
        {
            if (currentWeapon >= weaponHolder.transform.childCount - 1)
            {
                currentWeapon = weaponHolder.transform.childCount - 1;
            }
            else
            {
                currentWeapon++;
            }
        }
    }
3 Likes

Privacy & Terms