Target Selection

Setting Up Target Selection

To enable a vehicle to select a target from the targets being tracked by its Tracker component, add a Tracker Target Selector component to the vehicle.
You can specify in the inspector what type, teams or other characteristics a target must have to be selectable.
You can add multiple target selectors to a vehicle if you wish, for example one for waypoints and another for combat targets.

Selecting A Target

To give you the most flexibility with the type of game you want to make, there are several different ways that you can enable your players to select targets.

Next/Previous

To select the next or previous target that is being tracked by the vehicle, use the following code:
1
// Select the next target
2
myTargetSelector.Cycle(true);
3
​
4
// Select the previous target
5
myTargetSelector.Cycle(false);
Copied!

Nearest

To select the target nearest the vehicle, use the following code:
1
// Select the nearest target
2
myTargetSelector.SelectNearest();
Copied!

Front

To select the target that is in front of the vehicle, use the following code:
1
// Select the target in front
2
myTargetSelector.SelectFront();
Copied!

Specified Target

To select a specific target that you have a reference to, use the following code:
1
// Select a specified target
2
myTargetSelector.Select(myTarget);
Copied!

Target Selection Input

Using Unity's standard input manager, the Player Weapon Target Selector Input component has been provided to give your players controls for every type of target selection.

Cursor Target Selection

To enable cursor target selection on your vehicle, make sure your vehicle has an Aim Controller component on it, and look for the 'Aim Based Target Selection' subsection in the inspector. Make sure the 'Aim Target Selection Enabled' checkbox is checked.
Setting up the cursor UI is discussed further in the Radar UI section.

Target Selection For AI

By default, in the demos provided in the kit, the AI uses the target that is selected by the Target Selector that has been assigned to the Weapon component on a vehicle as its combat target.
​