Hello - in my game the player can switch between the first person controller and the third person controller on pressing the space bar.
On hitting a collider however, after three seconds it is switched to the first person controller automatically (without the player pressing space)
This works - but for some reason you have to press spacebar twice in order to switch back to the third person controller.
I don’t think I’m referencing the boolean check from the SwitchControllers script correctly - but I can’t work out what I’m doing wrong.
This is the ForceIntoFirstPerson script (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
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;
var temp : SwitchCharacters = gameObject.GetComponent(SwitchCharacters);
temp.check = true;
}
}
And this is the SwitchCharacters script:
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;
}
}
Could anyone help - I just can’t work out how to solve this problem at all.
Thanks, Laurien