Hello - in my game the player can switch between first and third person on pressing the space bar. Once the third person controller hits a collider, after 3 seconds it switches to the first person controller automatically without the player pressing space.
The script to SwitchBetweenControllers works, and the one to ForcePlayerIntoFirstPerson works - but my problem is that once the player is in first person - he has to press the spacebar twice before switching to the third person controller.
I can’t work out why this is - any help would be so much appreciated!
This is the script for SwitchBetweenControllers (JavaScript):
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; // check-variable
//start with first person active
function Start() {
cam01.gameObject.active = true;
cam02.gameObject.active = false;
player02.active = false;
check = true;
}
function Update() {
player01.transform.position = player02.transform.position;
if (Input.GetKeyDown ("space")) {
if(check) {
cam01.gameObject.active = false;
cam02.gameObject.active = true;
player01.active = false;
player02.active = true;
}
else {
cam01.gameObject.active = true;
cam02.gameObject.active = false;
player01.active = true;
player02.active = false;
}
check = !check;
}
}
And this is the script for ForcePlayerIntoFirstPerson (which is attached to the collider):
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;
function OnTriggerEnter(other: Collider){
if (other.tag == "Player")
{
yield WaitForSeconds (3);
cam01.gameObject.active = true;
cam02.gameObject.active = false;
player01.active = true;
player02.active = false;
check = true;
}
}
Thanks so much, Laurien