Switch to first person controller after 3 seconds

Hello, in my game the player can switch between the first and third person controller by pressing the spacebar.

After the third person controller hits a trigger, I want to switch to the first person controller after three seconds (without the spacebar being pressed).

This is the script I wrote, but for some reason it makes the third person controller inactive, and unchecked in the hierarchy, therefore creating a black screen as there are no cameras in the scene any more.

Here’s the script (JavaScript - any ideas on what I’m doing wrong?

	var cam01 : GameObject; // first person camera
    var cam02 : GameObject; // third person camera
    var player01 : GameObject; //first person controller
    var player02 : GameObject; //third person controller
    var check;                 // New check-variable

function Start () {

yield WaitForSeconds (3);

 cam01.gameObject.active = true; 
 cam02.gameObject.active = false; 
 player02.active = false;
 player01.active = true;
       check = true;

}

Thanks, Laurien

you have placed it in function Start you need to place it in function Update Start is only read at the time when the game starts, update it read every frame. You also needs to write a if ()

var cam01 : GameObject; // first person camera
var cam02 : GameObject; // third person camera
var player01 : GameObject; //first person controller
var player02 : GameObject; //third person controller

var camera01 : boolean;
var camera02 : boolean;

function Start ()
{
	camera01 = true;
	camera02 = false;
}

function Update () 
{
	if (Input.GetKeyDown(KeyCode.Space)) 
	{
		if (camera01 == true)
		{
			InvokeRepeating("Camera2", 0, 3);
			camera02 = true;
		}
		
		if (camera02 == true)
		{
			InvokeRepeating("Camera1", 0, 3);
			camera01 = true;
		}
	}
}

function Camera1 ()
{
	cam01.gameObject.active = true; 
	cam02.gameObject.active = false;
	player02.active = false;
	player01.active = true; 
}

function Camera2 ()
{
	cam01.gameObject.active = false; 
	cam02.gameObject.active = true;
	player02.active = true;
	player01.active = false; 
}

try this. Assign the cameras and players. Don’t play with the Booleans. They sort them self. (Look in function Start)

This should work.

The first person controller is the standard. If you want it switched. Go to function Start and switch between who is false and true