zooming and panning a picture in a GUI window

Hello,

is there a way to zoom and pan a picture in a GUI window ?

I’m trying to display a photography of an object represented in 3D in my scene, and when the user click on it, it opens a picture in a GUI.

But now, I would like the user to be able to zoom with the mouse wheel and pan the image to look in detail the photography.

Is there a way to do that in a GUI ?

Thanks a lot for your help

As you can change the size and position of an image in GUI, with the help of some maths, it’s totally doable.

If it’s a static image, use GUI.DrawTextureWithTexCoords() if you’re not already using it. This method lets you draw part of a texture, which lets you zoom and clip.

To handle mouse input, check Event.current inside your OnGUI method. Handle EventType.ScrollWheel for mouse wheel input (zooming) and EventType.MouseDrag for mouse drags (panning).

If it’s a dynamic render of a scene (for example, a security camera feed in a game), use a RenderTexture if you have Unity Pro.