How to make this enter/exit car script apply for any vehicle

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;
}

–RIO

Place a trigger next to the car. Get the car component script of the car. Run it when you wanna get into the car by using the trigger.

1 Like

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

I have posted a quit video on youtube that should help you with you problem. It is a two part series: https://www.youtube.com/watch?v=FdkdGyyKBNU

enjoy.

ENTER/EXIT Car like as GTA + Canister 10l and FuelMeter with animation

This video show a complete script in C:

Include functions:

  • Car Enter
  • Car Exit
  • Boot Lid Open
  • Boot Lid Open
  • Car fuel meter
  • Fuel canister 10l

Messages:
“You added fuel into the car”
“Canister is Empty!”
“I cant drive with canister”
“I cant drive, if boot lid si open”

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.

more info on the script can be found below.

3042061–227867–EnterExitSingle.cs (3.63 KB)
3051356–228946–SpawnPoint.cs (132 Bytes)

1 Like

Dooley how to setup there scripts

1 Like

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!!

It would be awesome to get some help with a enter/exit script that is raycast based because I cant use ontrigger…

https://discord.gg/eGASr3 follow up with me here.

1 Like

Tutorial link ,please!

@dooly123 if possible , you can send project link?

1 Like

https://discord.gg/KJB7zU u can get me here.

get bellow error :
“Invite Invalid”

https://discord.gg/444VJmf should help ya out there.

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.

1 Like

For simplicity, I would probably also use box, or sphere colliders at doors, with OnCollisionEnter or similar.

Visit this link for car enter exit system: https://incern.blogspot.com/2022/06/car-enter-exit-system-c-unity-demo.html

Watch this Video for car enter exit system:
https://www.youtube.com/watch?v=gLu3g_iNQDE

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.