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.
Look at this post to see how to use the scroll wheel, and then use that input to change the camera.orthographicSize.
void Zoom(){
if (Input.GetAxis (“RotellinaDelMouse”) > 0 && (Input.GetAxis (“RotellinaDelMouse”) + GetComponent ().orthographicSize) > minimo) {
for(int sensitivityOfScrolling=3; sensitivityOfScrolling>0; sensitivityOfScrolling–) GetComponent ().orthographicSize–;
}
if (Input.GetAxis (“RotellinaDelMouse”) < 0 && (Input.GetAxis (“RotellinaDelMouse”) + GetComponent ().orthographicSize) < massimo) {
for(int sensitivityOfScrolling=3; sensitivityOfScrolling>0; sensitivityOfScrolling–) GetComponent ().orthographicSize++;
}
}
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
Ah and ofc replace the “RotellinaDelMouse” with how u named it on ( Edit>ProjectSettings>Inputs> “Mouse Wheel” ; it should be something like that