AddDrivingAction
Description
Add an external driving action to a traffic vehicle to customize its behavior. The added action will be added inside the vehicle's actions queue and executed accordingly.
The complete list of actions is available here: DriveActions
Declaration
public static void AddDrivingAction(int vehicleIndex, DriveActions action, bool force)Parameters
Name
Description
vehicleIndex
Index of the excluded vehicle.
action
The DriveActionsaction to be added.
force
If true, all the preexisting actions for that vehicle will be cleared and just the current one will be added.
Example
using Gley.TrafficSystem;
using UnityEngine;
public class Test : MonoBehaviour
{
//a reference to vehicle pool and player assigned in inspector
public VehiclePool vehiclePool;
public Transform player;
void Start()
{
API.Initialize(player, 20, vehiclePool);
}
private void Update()
{
if(Input.GetKeyDown(KeyCode.Alpha1))
{
//If 1 is pressed the vehicle will stop.
API.AddDrivingAction(0, DriveActions.Stop, true);
}
if(Input.GetKeyDown(KeyCode.Alpha2))
{
//If 2 is pressed the vehicle will continue its previous behavior.
API.RemoveDrivingAction(0, DriveActions.Stop);
}
}
}
Last updated