GetVehicleIndex
Description
Gets the index of a vehicle GameObject.
Useful to get the list index of a specific vehicle.
Declaration
public static int GetVehicleIndex(GameObject vehicle)Parameters
Name
Description
vehicle
The root GameObject of a traffic vehicle.
Returns
int - the list index of the vehicle (-1 = error)
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);
}
public void ExcludeVehicle()
{
//find a vehicle and exclude it from the system
int vehicleIndex = API.GetVehicleIndex(GameObject.Find("Sedan(Clone)10"));
if (vehicleIndex != -1)
{
API.ExcludeVehicleFromSystem(10);
}
}
}
Last updated