Problem with my car enter/exit script

Hi, everyone! I’m pretty new to Unity Answers as a user, but I’ve been working with Unity pro for over 2 years. I am working on a 3rd person action shooter with freeroaming as one of the main features, but I’m struggeling to get one of my scripts working properly.
I have a scene where my player (in the storyline a gangster) needs to enter a car, so I have a car object with a ‘carcontrol’ script attached to it. I put a cube as a child next to the cardoor, disabled the renderer and made it a trigger. I’ve got a player object, and I have two camera’s. One for the car, and one for the player. I’ve written this script, and attached it to the trigger next to the cardoor:

var isVisable : boolean;
var gangster : GameObject;
var car : GameObject;
var carcam : Camera;
var gangstercam : Camera;
var isinCar : boolean;

function Start(){
isVisable = true;
isinCar = false;
gangster.active = true;
car.GetComponent(CarControl).enabled = false;
carcam.active = false;
gangstercam.active = true;
}

function Update(){
if(Input.GetButtonUp("Getincar") && !isVisable == true){
isinCar = true;
gangster.active = false;
car.GetComponent(CarControl).enabled = true;
carcam.active = true;
gangstercam.active = false;
}else{
isinCar = false;
gangster.active = true;
car.GetComponent(CarControl).enabled = false;
carcam.active = false;
gangstercam.active = true;
}

if(Input.GetButtonUp("Getincar") && !isinCar == true){
isinCar = false;
gangster.active = true;
car.GetComponent(CarControl).enabled = false;
carcam.active = false;
gangstercam.active = true;
}
}

function OnTriggerEnter(other : Collider){
if(other.gameObject.name == "PLAYER"){
isVisable = true;
}
}

function OnTriggerExit(other : Collider){
if(other.gameObject.name == "PLAYER"){
isVisable = false;
}
}

I’ve put the script on the trigger next to the cardoor. Everything in the script looked fine, and the console gave no errors at all. When I tested the level, and went into the trigger with my player, I pushed the “Getincar” button. My player deactivated, the carcontrol script turned on and the cameras switched like they should, but then immediatly turned back to their original state. No matter how much I push the button, they just keep on turning back within half a-second or something. Could anyone please point out what I am doing wrong here?
Thanks in advance!

-Patrick Schut (PattyGames)

Hey, This script should help you out:

var car : Transform;
var gangster : Transform;
var exitPoint : Transform;
var doorTriggerLeft : Transform;
var gangsterCam : Camera;
var CarCam : Camera;

function Start(){

}

function Update(){
if(Input.GetButton("GetinCar")){
GetComponent(CarControl).enabled = true;
gangster.gameObject.SetActiveRecursively(false);
gangster.gameObject.active = false;
CarCam.enabled = true;
gangstercam.enabled = false;
gangster.parent = exitPoint.transform;
exitPoint.transform.localPosition = Vector3(-0.5,0,0);
exitPoint.parent = car.transform;
exitPoint.transform.localPosition = Vector3(-0.5,0,0);
}
else{
if(Input.GetButton("GetinCar")){
GetComponent(CarControl).enabled = false;
gangster.gameObject.SetActiveRecursively(true);
gangster.gameObject.active = true;
CarCam.enabled = false;
gangstercam.enabled = true;
gangster.transform.parent = null;
exitPoint.parent = doorTriggerLeft.transform;
}
}
}