SetDestination
Description
Declaration
public static void SetDestination(int vehicleIndex, Vector3 position)Parameters
Name
Description
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);
Events.onDestinationReached += DestinationReached;
}
public void SetDestination()
{
//set a random destination;
Vector3 destination = new Vector3(Random.Range(-500, 500), 0, Random.Range(-500, 500));
//make the vehicle with index 5 drive to the destination
API.SetDestination(5, destination);
}
private void DestinationReached(int vehicleIndex)
{
if(vehicleIndex==5)
{
//set another random destination for this vehicle if the previous one was reached.
Vector3 destination = new Vector3(Random.Range(-500, 500), 0, Random.Range(-500, 500));
API.SetDestination(vehicleIndex, destination);
}
}
private void OnDestroy()
{
Events.onDestinationReached -= DestinationReached;
}
}
Last updated