- Home /
Wait before zooming camera at the start of level
Hi, At the start of each level, I want camera to wait 1 second and then zoom into the normal Field of View. I set my starting camera field of view to be zoomed out. This is the code I have:
#pragma strict
var zoomIn : float = 46;
var zoomOut : float = 65;
var smooth : float = 5;
function Start () {
yield WaitForSeconds (1);
Zoom();
}
function Zoom()
{
if(camera.fieldOfView > 46)
{
camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, zoomIn, Time.deltaTime * smooth);
}
}
When I start the game, it waits for a second, and then jumps to a field of view just below the starting field of view. I'm guessing that's because the Mathf.Lerp is only getting called one time, and is therefore interpolating one time. When I put the line of code that is in Zoom() in an Update function it works, but then it doesn't wait before it zooms...
How can I make the camera wait before it zooms in?
for extremely simple timers in Unity, just use Invoke()
eg Invoke( "zoomTheCamera", 1.5 );
Answer by DaveA · Mar 18, 2013 at 10:22 PM
var waitTime = 1;
Update ()
{
if (Time.time > waitTime)
{
if(camera.fieldOfView > 46)
{
camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, zoomIn, Time.deltaTime * smooth);
}
}
}
Thanks, that was the key, although I need it to be Time.timeSinceLevelLoad ins$$anonymous$$d of Time.time Thanks!
Your answer
Follow this Question
Related Questions
Zooming camera using move z position. 0 Answers
How to zoom in smoothly with orthographic camera? 1 Answer
Clamping a 2D camera while zooming. 0 Answers
How to zoom camera in x amount of seconds 1 Answer
Camera zoom smoothing 1 Answer