Disabling mouse wheel when user is scrolling ScrollView

Hello everyone,

Basically, I have two scripts so that one (ScrollView.cs) is responsible for ScrollView and other(CameraControl.cs) is for zooming by using mouse wheel.

Zooming codes are in LateUpdate. Scrolling codes are in OnGUI.

I think, the problem is obvious, I do not want to zooming in-out when user is scrolling the ScrollView.

I tried the changing order of script execution. But nevermind, I do not know why but it did not work.

Thanks in advance.

Maybe just disabled the CameraControl.cs when your mouse cursor is on your GUI where you do your scrolling ?

It doesn’t matter which script is executing first. Both are running independently of each other. If I had the following code if(Input.GetMouseDown(0) == true) in two different scripts, both will execute the if statements. listzto had the right idea. I would check if the Input.mousePosition is over GUI view then disable/enable the cameraControl script.

Here is my code. I tried disabling CameraControl script. Unfortunately, It does not work:

oldScrollPos = scrollPosition;
scrollPosition = GUI.BeginScrollView (new Rect (1460,650,340,255),scrollPosition, new Rect (0, 0, 0, notList.Count*65-5));


if (oldScrollPos != scrollPosition)
     GameObject.Find("Camera").GetComponent<CameraControl>().enabled = false;
else
     GameObject.Find("Camera").GetComponent<CameraControl>().enabled = true;

In order to disable mouse wheel we need to do:

using (var scope = new GUILayout.ScrollViewScope(...)) {
    scope.handleScrollWheel = false;
}

and that’s it.

I spent 2h to find how to do it and also been here, so maybe someone will see this answer.