- Home /
Input.GetAxis("Mouse ScrollWheel") not working without wheel being clicked in
So, is there anyone else with this problem? I currently have var num = Input.GetAxis("Mouse ScrollWheel") Camera.main.orthographicSize -= num; Debug.Log(num);
Debug shows a constant zero when I scroll, only outputting non-zeros if I click in the scrollwheel and scroll at the same time.
Occurs on Logitech M215 Unifying mouse, M557 Bluetooth mouse, and Asus I2C interface trackpad
Having a similar problem. Code is inside Update() functions I presume?
Well......the original question was posted Februrary 2017. No answers or other comments until today, about 1.5 years later. I'd suggest you start a new question on this if you like.
I don't recall it happening again in my subsequent projects, so that was either a project bug, or bug in the unity version. Does it occur in a new project? Are you recent unity versions? If so, you'd be better off starting a new question like the guy above said.
Answer by RX187 · Aug 31, 2018 at 12:43 AM
public float minSize, maxSize;
public float zoomSensitivity;
public void CamZoom()
{
float fov = Camera.main.orthographicSize;
fov -= Input.GetAxis("Mouse ScrollWheel") * zoomSensitivity;
fov = Mathf.Clamp(fov, minSize, maxSize);
Camera.main.orthographicSize = fov;
}
That doesn't help that situation before. The problem was that Input.GetAxis("$$anonymous$$ouse ScrollWheel")
would only return a non-zero value when clicked in on the scroll wheel.
It was either some other settings with Input, or a Unity Project/Version bug.
Answer by robwillson · Apr 02, 2019 at 01:44 AM
I had this issue, and for me the culprit was something I'd put in to cut down on individual checks for various keyboard inputs: if(!Input.anyKey) return;
.
anyKey is a bool which returns "is any key or mouse button currently held down". This includes all keyboard and mouse buttons, but (with my mouse at least) does not include scrolling the mouse wheel. Pressing in the mouse wheel does count as a button press, so bypasses the anyKey check, as described by the OP.
If this anyKey thing is your issue then the solutions are simple...
Solution 1 - Place your code for mouse scrollwheel above the anyKey check:
private void Update () {
// Code to process your scrollwheel input here
if (!Input.anyKey) {
// No keyboard or mouse buttons are currently being pressed, skip further checks
return;
}
// Code to process mouse/keyboard input here
}
Solution 2 - Add an extra check specifically for the scroll wheel with mouseScrollDelta
private void Update () {
if (!Input.anyKey && Input.mouseScrollDelta == Vector2.zero) {
// No keyboard or mouse buttons are currently being pressed, skip further checks
return;
}
// Code to process mouse/keyboard/scrollwheel input here
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612110444im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
ScrollWheel Input not detected in script 2 Answers
Returning mouse scroll as a keycode 1 Answer
Unity 5 tree creator not working correctly. 0 Answers
ServerReturnToLobby() not workiing 0 Answers