Accomplishing a cool camera effect (Solved!)

:shock: Noob Crisis: Averted! (Another one bites the dust…) :shock:
I’ve now began playing with Transforms on my Camera! For my title screen, I’m trying to get the Camera to move forward two world units while also rotating up about fifteen degrees, over a span of two (subject to tuning) seconds - a little camera whoosh! However, my code isn’t making this happen:

function Update()
{

  if( titleState == 0 )
  {
    // Title-> Load/New Game Scenario:
    //  We want to set the new state, whoosh our
    //  camera in a cool way, THEN let the OnGUI
    //  know that it should render.
    if( Input.GetKeyDown( KeyCode.Return ) )
    {
      var isDone = Time.timeSinceLevelLoad + 2;

      while( Time.timeSinceLevelLoad < isDone )
      {
        transform.Translate( 0,0, 2 * Time.deltaTime );
	transform.Rotate( -15 * Time.deltaTime, 0,0 );
        yield;
      }

      titleState = 1;
    }
  }
}

For some reason, this dosen’t even execute at all! When I remove the while loop, it will hop forward and rotate up a little, as it should. How do I prolong this effect to the point I would like it to be?

You can’t put yield in Update; it runs every frame regardless. Use coroutines instead. (See here for some discussion.)

–Eric

Hoo-HA! :smile: Your supplied discussion of Coroutines worked perfectly!

function Update()
{

  if( titleState == 0 )
  {
    // Title-> Load/New Game Scenario:
	//    We want to set the new state, whoosh our
	//    camera in a cool way, THEN let the OnGUI
	//    know that it should render.
	
    if( Input.GetKeyDown( KeyCode.Return ) )
	{
      StartCoroutine( CoCameraUp() );
	  
	  titleState = 1;
	}
	
  }
}

function CoCameraUp()
{
  var moveDone = Time.timeSinceLevelLoad + 1.5;
  
  while( Time.timeSinceLevelLoad < moveDone )
  {
    transform.Translate( 0,0, 3 * Time.deltaTime );
    transform.Rotate( -10 * Time.deltaTime, 0,0 );
	yield;
  }
}

Solved, and the snazzy effect I was looking for!