Add gems
Now that the player can control an entity in the scene, give the player a destination to drive towards.

Create GemSpawner
GemSpawnerIn Assets/Scripts, create a new script named
GemSpawner.This script defines how the gems are generated randomly on the current plane.
Add the game element
Create a new empty
GameObjectin the Hierarchy.Rename it to
Gem Spawner.Select the object you created. In the Hierarchy pane, click Add Component to add the
GemSpawnercomponent to it.Set up
GemSpawner's dependencies by clicking on the chooser for the following field:Gem Prefab: In Assets, select Gem Prefab.
Reticle: In Scene, select Reticle Prefab.
Create GemBehaviour
GemBehaviourCreate a script named
GemBehaviourin PlaneDetectionStarterPackage folder. You needn't add anything else to this script.Associate
GemBehaviourwith Gem Prefab by editing Gem Prefab, clicking Add Component, and chooseGemBehaviouryou've created.
Modify Car Behaviour
In CarBehaviour you've previously created, add the following event function which defines the action when the car hits the gem.
Test the game
Click File > Build to test your changes. 2, After you create a car, a gem should spawn.
Drive your car to the gem.
A new one will appear at a random location.
Last updated
Was this helpful?