Probelm with Enter/Exit script

Hello! I using this script:

var Car :Transform;

var Player :Transform;

var exitPoint :Transform;

var doorTriggerLeft :Transform;

var PlayerCamera :Camera;

var CarCamera :Camera;

var isPlayerVisible :boolean;

 

function Update () {

 

    if(Input.GetButtonDown("Fire2")&& isPlayerVisible){

        Player.gameObject.SetActiveRecursively(false);

        Player.gameObject.active = false;

        Player.parent = exitPoint.transform;

        Player.transform.localPosition = Vector3(-1.5,0,0);

        exitPoint.parent = Car.transform;

        exitPoint.localPosition = Vector3(-3,0,0);

    //  GameObject.Find("Car").GetComponent("Car").enabled = true;

    //  GameObject.Find("Car").GetComponent("SoundController").enabled = true;

        GameObject.Find("Charger").GetComponent("CarController").enabled = true;

        PlayerCamera.enabled = false;

        CarCamera.enabled = true;   

    }

   else{

     if(Input.GetKeyUp("e")){

        Player.gameObject.SetActiveRecursively(true);

        Player.gameObject.active = true;

        Player.transform.parent = null;

         exitPoint.parent = doorTriggerLeft.transform;

        //exitPoint.parent = Car.transform;

//      GameObject.Find("Car").GetComponent("Car").enabled = false;

//      GameObject.Find("Car").GetComponent("SoundController").enabled = false;

        GameObject.Find("Charger").GetComponent("CarController").enabled = false;

        //GameObject.FindGameObjectWithTag("sentryGun").enabled = true;

        PlayerCamera.enabled = true;

        CarCamera.enabled = false;   

     

     }  

    

   }

}

 

function OnTriggerEnter(Player : Collider){

    isPlayerVisible = true;

}

 

function OnTriggerExit(Player : Collider){

    isPlayerVisible = false;

}

Everything works fine only the exit. When i get in to the car then the exit point cordinates change. Can somebody help me?

Don’t hard-code your positions.
Make 3 new floats for X, Y and Z and save your position in there while you’re in the car.

So instead of:

exitPoint.localPosition = Vector3(-3,0,0);

It should be something like:

float x;
float y;
float z;

void Update () {
    transform.position.x = x;
    transform.position.y = y;
    transform.position.z = z;

    exitPoint.localPosition = Vector3(x,y,z);
}

You can always check the inspector while playing to verify the X, Y and Z positions.