Vehicles
A Vehicle component represents an object that the player can control to move around in the game world.
Creating A Vehicle
To begin creating a new vehicle of any kind, create a new game object in the scene and add a Vehicle component.
Destroying/Restoring Vehicles
Like Game Agents, vehicles can be destroyed or restored during gameplay. Here is some code to help you understand how you can do this:
Vehicle Occupant
Sometimes you might want to know what game agent is controlling a vehicle.
Note that the Vehicle component has been scripted to allow for multiple occupants, but currently the kits only support one occupant per vehicle. So the list will normally have one member when a vehicle is occupied, and be empty when it is not.
Sometimes you might want to do something different when a player enters the vehicle vs when an AI enters the vehicle, or when the occupant exits a vehicle. You will find Unity Events in the inspector you can add functions to that you wish to be called when any of these events occur.
Module Mounts
To get all the module mounts on a vehicle, or add/remove a module mount, use the following code:
Vehicle Classes
The Vehicle Class (which is a Scriptable Object) provides a way to differentiate between vehicles, for example for running specific input scripts or camera controllers.
To create a new Vehicle Class, right click in the Project view and select Create > VSX > Vehicle Class.
This will create a new Vehicle Class object in your Assets folder, which you can rename.
To assign a Vehicle Class to a Vehicle, simply drag the Vehicle Class object you created into the 'Vehicle Class' field in the inspector of the Vehicle component.
Last updated