- Home /
Enter/Exit Car
I go this car script from my friend and for some reason it works just fine for him but not for me. Do you guys have any idea on how to fix it?
var Car : Transform;
var player : Transform;
var exitPoint : Transform;
var doorTriggerLeft : Transform;
var PlayerCamera : Camera;
var CarCamera : Camera;
var isPlayerVisable : boolean;
function update (){
if (Input.GetButtonDown("Fire1")&& isPlayerVisable){
//Make player invisable and still standing
player.gameObject.SetActiveRecursively(false);
player.gameObject.active = false;
// Parent player to ExitPoint
player.parent = exitPoint.transform;
player.transform.localPosition = Vector3(-1.5,2,0);
//Parent playerParent to car
exitPoint.parent = Car.transform;
exitPoint.transform.localPosition = Vector3(-0.5,2,0);
// Enable car as controllable object
GameObject.Find("Car").GetComponent("DrivingScript").enabled = true;
PlayerCamera.enabled = false;
CarCamera.enabled = true;
}
else
{
if (Input.GetButtonDown("Fire1")){
// Make Character visable again.
player.gameObject.SetActiveRecursively(true);
player.gameObject.active = true;
// Unparent Player from everything.
player.transform.parent = null;
// Parent Exit Point to Door Trigger.
exitPoint.parent = doorTriggerLeft.transform;
// Disable car as a controllable
GameObject.Find("Car").GetComponent("DrivingScript").enabled = false;
PlayerCamera.enabled = true;
CarCamera.enabled = false;
}
}
}
function OnTriggerEnter(Player : Collider) {
isPlayerVisable = true;
}
function OnTriggerExit(Player : Collider) {
isPlayerVisable = false;
}
Also the I get no error messages from the code when I use it but for some reason I can't get it to actually work. I am also using the Unity Car Tutorial.
Answer by Nightkilla · Oct 13, 2013 at 10:06 PM
It's function update. It needs to be function Update() {.
Answer by garner · Mar 31, 2012 at 06:01 PM
no errors... kinda hard to know what you are saying isn't working. make sure all the variables are assigned; there needs to be a collider attached to the gameobject; The car object needs to be named 'Car' because its looking for that.. comment things out and work through things.
Answer by Yung-Hustla · Jan 25, 2013 at 01:54 AM
i wrote this script itz totally functional...
I'm using the car from the tutorial too. I changed the find script to "Car" because my car script is Car. but it doesn't detect my Car script.
Answer by PS3_and_PC_Geek · Oct 14, 2013 at 09:13 PM
I noticed in the code you put function update()
The function Update is supposed to be like this below function Update() Update needs to be a capital letter
Answer by Iron_Games · Sep 02, 2014 at 08:23 PM
I think I can help you, the button to enter in the car isn't the "e" key, it's the right button on the mouse. Click with this rigt button on the car and it works ! Sorry for my bad english, I'm french...
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer
Camera follows not right 0 Answers
Entering/exiting vehicles 1 Answer
Help with my car. 1 Answer