hey everyone I also have this car enter/exit script I want to work for any car I get in instead of just one … like making it a in general script this is what I have
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.GetButtonUp("Action") 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("r")){
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;
}
what If different cars have different car scripts like one is named car the other is named CarController also I have door triggers already it’s just if I have both lines of code activated (18, 20) and (31,33) then it will place my character in the first car which is line (18, 31) and also move the other car (20, 33) that’s if I remove the comments, im looking for the script to work on any car without moving the other cars
here is a single-player component of my script that I sell in the asset store with some modifications and removed systems but this will defiantly get your enter exit working for what you are trying to do. I have a networked version on the asset store if anyone is interested.
that’s the easy part all you have to do is add both to your car. EnterExitSingle is the single-player variant of my code but still has the simple method of drop and drag. in other words, apply it fill the boxes out added all the scripts you want to be enabled when the player is in the vehicle and when he’s out to lose control of after settings this up
make sure to add the spawnpoint script to where you want the player to exit!!
What you want is called polymorphism. Create a base class called AbstractCarController that defines what methods and variables are shared among all cars, then you can inherit from that to make specific car classes.
SORRY bad english. To set the script, create new gameobject with box collider, and put the SpawnPoint Script to the gameobject. Put your EnterVehicle Script to Your car and you will see a variable “componentstodisableifnotdriver” and put your car in the variable, make sure that you see the the car script in the variable. Hope This Helps.
This thread is 4 years old. Any reason you necroing it?
If you want to be helpful, at least put your asset/project on the github.
People won’t be using some random website, to download things. Too high risk of catching some PC bug.