Hello - in my game I switch between first and third person. When the third person collides with a certain trigger - the third person controller is destroyed, and a new one is instantiated.
The problem I have is that once the new controller is instantiated, this script no longer works - switching between first and third person. (as of course I only assigned the first third person controller and camera in the hierarchy)
Is there a way of changing the script so that rather than assigning the third person controller and camera in the hierarchy, the script just references whichever third person controller is currently active?
(Sorry I’m not sure how exactly to phrase it - I’m still very new to scripting)
This is the script I’m using to switch between characters (JavaScript):
#pragma strict
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
//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 ("return")) {
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;
}
Thanks very much, Laurien