Question by
autumndaniellesinclair · Jun 08, 2019 at 03:07 PM ·
lerpzoomorthographic
Lerping a camera forwards and backwards to zoom in and out on button press,Lerping orthographic size to zoom in while button held, then zoom out when button is let go of?
I figured this would be fairly simple but I can't really seem to figure it out. I'm trying to have the camera zoom in slightly while i hold a button, and then when I let go of the button it zooms back out to its default position. I can make it zoom in pretty easily, the zooming out part is the bit i'm having trouble with. it just.. Doesn't work.
public float Zoom1;
public float Zoom2;
public float duration = 1.0f;
private float elapsed = 0.0f;
void Update()
{
if (Input.GetKey(KeyCode.Q))
{
elapsed += Time.deltaTime / duration;
Camera.main.orthographicSize = Mathf.Lerp(Zoom1, Zoom2, elapsed);
}
if (Input.GetKeyUp(KeyCode.Q))
{
elapsed = 0;
elapsed += Time.deltaTime / duration;
Camera.main.orthographicSize = Mathf.Lerp(Zoom2, Zoom1, elapsed);
}
}
}
Comment