Enter/Exit Cars - C# Unity Tutorial @DitzelGames
Enter/Exit Cars - C# Unity Tutorial  @DitzelGames
Uploaded June 2018 | Updated September 2026, 12 hours ago
This time I will show you a highly requested video. This is a final part to make something like GTA possible. I show you how to enter and exit a car using the third person controller from my previous videos.

Code Snippet:

//car
protected CarController carController;
protected SkinnedMeshRenderer Renderer;
public FixedButton CarButton;

private void CarUpdate()
{
if (carController == null)
{

//check if the player wants to get into a car
if (CarButton.Pressed)
{
CarButton.Pressed = false;
var colliders = Physics.OverlapSphere(transform.position, 2f);
foreach (var collider in colliders)
{
var car = collider.GetComponent❮ CarController❯();
if (car != null)
{
carController = car;
Renderer.gameObject.SetActive(false);
}
}
}

}
else
{
//drive the car
carController.Move(LeftJoystick.Horizontal + Input.GetAxis("Horizontal"), LeftJoystick.Vertical + Input.GetAxis("Vertical"), LeftJoystick.Vertical + Input.GetAxis("Vertical"), 0);
transform.position = carController.transform.position;

Camera.main.transform.position = carController.transform.position + carController.transform.rotation * new Vector3(0, 7, -10);
Camera.main.transform.rotation = Quaternion.LookRotation(carController.transform.position + Vector3.up * 2f - Camera.main.transform.position, Vector3.up);

//get out
if (CarButton.Pressed)
{
CarButton.Pressed = false;
carController = null;
Renderer.gameObject.SetActive(true);
}
}
}
Enter/Exit Cars - C# Unity TutorialTHANK YOU! - Made with Unity #012Honey Bear Run - World 2 - Android Game - Full WalkthroughDelete Bricks  - #LegoGame 9Enemy Shooting AI in Unity - 🔫 Shooting 6/6BECOME RICH WITH UNITY!Animations with Unity Shader Graph - FishHARDEST RIDDLE! - HackerRank.com - Lets Code #002Icarus Launch - Ludum Dare 39Unity Game Slow? Performance #1 - Level of DetailSTARTING MY GAME PROJECT - Made with Unity #001Spin Attack 🎮 Ludum Dare 40 Submission 😅
DitzelGames |

Enter/Exit Cars - C# Unity Tutorial

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER