Hello! I have an orthographic camera that has to zoom out smoothly depending on the velocity of my player. I know that in have to change the camera.main.orthographicSize to zoom out. Can someone make me a script for this or tell me exactly what to do? The zoom should also have a minimum zoom and a maximum zoom. thx for all your answers!
Something like this should work, have not tested it, so you maybe have to adapt the values for the variables in the first 4 lines a bit:
float minZoom = 1f;
float maxZoom = 5f;
float zoomStep = 0.1f;
float smoothness = 0.1f
public void ZoomOut(){
StartCoroutine(ZoomOutSmoothly());
}
private IEnumerator ZoomOutSmoothly(){
WaitForSeconds myWait = new WaitForSeconds(smoothness);
Camera.main.orthographicSize = minZoom; //you could also comment this line out and just use your current zoomValue... It's just for having a start position for the zoomanimation
while(Camera.main.orthographicSize < maxZoom){
Camera.main.orthographicSize += zoomStep * velocity; //take your players one for the velocity
yield return myWait;
}
Camera.main.orthographicSize = maxZoom; //ensure it is exactly set to the maxZoom value after the animation
}