- Home /
Question by
Justin00877 · Jan 19, 2014 at 12:10 PM ·
exitenter
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?
Comment
Best Answer
Answer by Blaveloper · Jan 19, 2014 at 12:36 PM
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.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Entering/exiting vehicles 1 Answer
is it possible to use the enter and exit script to enter a turret? 0 Answers
How do you make character enter and exit vehicles. 1 Answer
Enter/Exit vehicle 0 Answers