- Home /
How do you adjust orthographic camera size using mouse wheel?
I'm making a 2D side scroller and I want a way to be able to zoom in and out based on how much a player scrolls up or down.
Answer by Fanttum · Sep 13, 2014 at 08:56 PM
Look at this post to see how to use the scroll wheel, and then use that input to change the camera.orthographicSize.
Answer by Sabani · Jan 04, 2017 at 11:16 AM
 void Zoom(){
     if (Input.GetAxis ("RotellinaDelMouse") > 0 && (Input.GetAxis ("RotellinaDelMouse") + GetComponent<Camera> ().orthographicSize) > minimo) {
         for(int sensitivityOfScrolling=3; sensitivityOfScrolling>0; sensitivityOfScrolling--) GetComponent<Camera> ().orthographicSize--;
     }
     if (Input.GetAxis ("RotellinaDelMouse") < 0 && (Input.GetAxis ("RotellinaDelMouse") + GetComponent<Camera> ().orthographicSize) < massimo) {
         for(int sensitivityOfScrolling=3; sensitivityOfScrolling>0; sensitivityOfScrolling--) GetComponent<Camera> ().orthographicSize++;
     }
 }
@Maskaraid
Hope that can be usefull ;)
Obviusly you have to put that zoom() method on the update() one.
I did it and it work , its not fluid , as is just a incrementation/decrementation of size of orthographicSize of the camera , u can set for a wheelStep how much do u want increase or decrease your camera zoom!
Changing in the for the "sensitivityOfScrolling" makes it faster or slower ;) and thats it tell me if it was late :P
Ah and ofc replace the "RotellinaDelMouse" with how u named it on ( Edit>ProjectSettings>Inputs> "Mouse Wheel" ; it should be something like that ;)
Your answer
 
 
             Follow this Question
Related Questions
is possible mouse wheel key in else than GetAxis? 2 Answers
iphone 2D settings 2 Answers
Camera Zoom for Orthographic (iPhone Touch) 1 Answer
Making a camera semi-orthographic 2 Answers
2d artefact gap between tiles 4 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                