Skip to content

Instantly share code, notes, and snippets.

@yasirkula
Last active September 21, 2019 16:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasirkula/8772bfe971d0b4836b1f7bfcb1f9cded to your computer and use it in GitHub Desktop.
Save yasirkula/8772bfe971d0b4836b1f7bfcb1f9cded to your computer and use it in GitHub Desktop.
"Right mouse button+Scroll wheel" will continue to zoom in/zoom out the Scene View instead of changing the camera speed on Unity 2019+
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class EditorCameraZoomWithScrollWheel
{
private const float CAMERA_SPEED = -0.25f;
private static bool rmbDown = false;
static EditorCameraZoomWithScrollWheel()
{
SceneView.beforeSceneGui -= OnScene;
SceneView.beforeSceneGui += OnScene;
}
private static void OnScene( SceneView scene )
{
Event e = Event.current;
if( e.isMouse && e.button == 1 )
{
if( e.type == EventType.MouseDown )
rmbDown = true;
else if( e.type == EventType.MouseUp )
rmbDown = false;
}
if( e.isScrollWheel && rmbDown )
{
Vector3 pivot = scene.pivot;
pivot += scene.camera.transform.forward * ( e.delta.y * CAMERA_SPEED );
scene.pivot = pivot;
e.Use();
}
}
}
#endif
@yasirkula
Copy link
Author

How To

Simply create a folder called Editor inside your Project window and add this script inside it.

@MostHated
Copy link

Sweet baby jesus, thank you for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment