Auto Enabling and looping a script?

Hey guys, I’m a noobie at Unity and the syntax used for scripting. I know a little javascript so I wrote what I could of a script that could disable and enable a camera with a little delay. Here’s what I came up with.

function Start()
{
	  GameObject.Find("Main Camera").camera.enabled = false;
	  yield WaitForSeconds(.05);
	  GameObject.Find("Main Camera").camera.enabled = true;
      yield WaitForSeconds(5);   
}

Problem is, I have no clue where to go from there, as I need to have it loop and be running from the start. Any help? :smiley:

Thanks, and sorry for being such a noob (sidenote, if someone could point me to some good basic video tutorials that would be great)

–Merglyn

CoRoutines are superbly helpful for this. Of course if you want to improve the performance of the script, you’ll want to find your main camera in Start (so it happens only once). Cache the found camera to a variable, then access it later in LoopCamera().

    function Start()
        {
        StartCoroutine( LoopCamera() );
        }
    function LoopCamera() : IEnumerator
       {
       while( true )
           {
           GameObject.Find("Main Camera").camera.enabled = false;
           yield WaitForSeconds(.05);
           GameObject.Find("Main Camera").camera.enabled = true;
           yield WaitForSeconds(5);   
           }
       }