Add a car

The player will control a toy car that will drive towards the location of the reticle. A model for this car is provided in the Plane Detection Starter Package.

Define Car Behaviour

  1. Create a CarBehaviour script in Assets/PlaneDetectionStarterPackage. The script defines how a car moves in relation to the hit point (reticle).

2. Double click Car Prefab in Assets/PlaneDetectionStarterPackage to edit the prefab. Add the CarBehaviour you've created as a component of this prefab.

Create CarManager script

Create a CarManager in your project's scripts folder (Assets/Scripts) as the following. The CarManager defines when and how the car is initialized.

Add a CarManager to your scene

  1. In the Hierarchy, create a new empty GameObject.

  2. Rename it to Car Spawner.

  3. Select the object you created. In the Hierarchy pane, click Add Component to add the CarManager component.

  4. Set up CarManager's dependencies by clicking on the chooser for each field:

    • Car Prefab: In Assets, select Car Prefab.

    • Reticle: In Scene, select Reticle Prefab.

Test driving

  1. Click File > Build to test your changes.

  2. When you tap on a plane, you should see a small car appear at that location. This car will follow the reticle.

Was this helpful?