First, sorry for my messy scripting style, im quite a beginer. Second, i used this script in a project, then the project got too messed up and i started a new project. Now, when i am trying to use tis script and attach it to some car parent, it will not let me do it because “it has not finished on compiling” and i am getting the error like, for example:
Assets/SCRIPTS/General/EnterExitCar.js(89,18): BCE0005: Unknown identifier: ‘Drivetrain’.
Why is the script searching for thos things before the script is being attached to the car parent?
//Enter Exit Car Script By Hotea Florin Ioan - hoteaflorinioan@yahoo.com
var Car : Transform;
var Player : Transform;
var DoorTrigger : Transform;
var ExitPoint : Transform;
var PlayerCamera : Camera;
var CarCamera : Camera;
var CarCamera1 : Camera;
private var IsPlayerInTrigger : boolean;
private var IsPlayerInCar : boolean = false;
//var BackWheelLeft : WheelCollider;
//var BackWheelRight : WheelCollider;
//This two functions will sense when the player is in the door trigger area
//Aceste doua functii vor simti cand playerul este in zona masinii
function OnTriggerEnter(Player : Collider) {
IsPlayerInTrigger = true;
print("PlayerEnteredTrigger");
}
function OnTriggerExit(Player : Collider) {
IsPlayerInTrigger = false;
print("PlayerExitedTrigger");
}
function FixedUpdate () {
// Here will tell them what to do
// Aici le spunem ce sa faca
// If we press the desired key and the player is in the trigger area
// Daca apasam tasta dorita si playerul este in zona masnii
if (Input.GetKeyDown("f")){
if (IsPlayerInTrigger && !IsPlayerInCar) {
print("Player Is In Trigger, Will Enter VEHICLE");
// We will DEACTIVATE, atention, not DISABLE the player
// Vom DEZACTIVA, atentie, DEZACTIVA, nu DEZABILITA playerul
Player.parent = ExitPoint.transform;
Player.transform.localPosition = Vector3(0,0,0);
Player.transform.localRotation = Quaternion.identity;
Player.active = false;
PlayerCamera.GetComponent(AudioListener).enabled = false;
PlayerCamera.enabled = false;
CarCamera.enabled = true;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Car.GetComponent(AudioSource).enabled = true;
CarCamera.GetComponent(AudioListener).enabled = true;
IsPlayerInCarTrue();
Car.GetComponent(CarController).enabled = true;
Car.GetComponent(Drivetrain).enabled = true;
//Car.GetComponent(SoundController).enabled = true;
Car.GetComponent(kmphdisplay).enabled = true;
//BackWheelLeft.brakeTorque = 0;
//BackWheelRight.brakeTorque = 0;
IsPlayerInTrigger = false;
}
if (IsPlayerInCar) {
print("Player Will Exit Car NOW!");
//BackWheelLeft.brakeTorque = 10000;
//BackWheelRight.brakeTorque = 10000;
Player.active = true;
PlayerCamera.GetComponent(AudioListener).enabled = true;
Player.transform.parent = null;
Player.transform.localRotation = Quaternion.identity;
//if (Input.GetKey("v")){
// if (CarCamera.enabled == true) {
// CarCamera1.enabled = true;
// CarCamera.enabled = false;
// print ("CAMERA1");
// }
// if (CarCamera.enabled == false){
// CarCamera1.enabled = false;
// CarCamera.enabled = true;
// print ("CAMERA2");
// }
//}
Car.GetComponent(AudioSource).enabled = false;
PlayerCamera.enabled = true;
CarCamera.enabled = false;
CarCamera.GetComponent(AudioListener).enabled = false;
IsPlayerInCarFalse();
Car.GetComponent(CarController).enabled = false;
Car.GetComponent(Drivetrain).enabled = false;
//Car.GetComponent(SoundController).enabled = false;
Car.GetComponent(kmphdisplay).enabled = false;
}
}
}
function IsPlayerInCarFalse() {
yield WaitForSeconds(0.5);
IsPlayerInCar = false;
}
function IsPlayerInCarTrue() {
yield WaitForSeconds(0.5);
IsPlayerInCar = true;
}