0 votes

I want to use the mousewheel as a Input event.

For example: Lets say I have a variable var weapon = 5 and I want to use the mousewheel to change the weapon. So if I scroll up I want to increase the number and when I scroll down I want to decrease the number.

What is the simplest way to do this?

Thanks for answers!

asked Jun 4 in Engine by Godot_Starter (265 points)

1 Answer

+2 votes
Best answer
var weapon : int = 0

func _input(event : InputEvent) -> void:
    if event is InputEventMouseButton:
        event as InputEventMouseButton
        if event.pressed:
            match event.button_index:
                BUTTON_WHEEL_UP:
                    weapon += 1
                BUTTON_WHEEL_DOWN:
                    weapon -= 1
            print(weapon) # delete this, if it works

i think it's self-explanatory. If not, feel free to ask.

answered Jun 4 by whiteshampoo (976 points)
selected Jun 7 by Godot_Starter
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.