RemoveVehiclePath
Description
Remove a predefined path for a vehicle. The vehicle will then behave like a normal traffic vehicle and will be added and removed by the pooling system.
Declaration
public static void RemoveVehiclePath(int vehicleIndex)Parameters
Name
Description
vehicleIndex
The index of the vehicle to remove the path from.
Example
using Gley.TrafficSystem;
using System.Collections.Generic;
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);
//listen for the destination reached event
Events.onDestinationReached += OnDestinationReached;
}
public void AddPathToVehicle()
{
//get the path from start to end
Vector3 startPosition = new Vector3(0, 0, 0);
Vector3 endPosition = new Vector3(0, 0, 350);
List<int> path = API.GetPath(startPosition, endPosition, VehicleTypes.Car);
if (path.Count > 0)
{
//assign the path to the vehicle with index 10
API.SetVehiclePath(10, new Queue<int>(path));
}
else
{
Debug.Log("No path found");
}
}
private void OnDestinationReached(int vehicleIndex)
{
//when vehicle 10 reaches the destination, remove the path and continue as a normal vehicle.
if(vehicleIndex == 10)
{
API.RemoveVehiclePath(10);
}
}
private void OnDestroy()
{
//don't forget to remove the events
Events.onDestinationReached -= OnDestinationReached;
}
}
Last updated