onDestinationReached

Description

Triggered every time a vehicle reaches the last point of its path. See Path Finding Setup

Parameters

NameDescription

vehicleIndex

The index of the vehicle that reached the destination.

Example

using Gley.TrafficSystem;
using UnityEngine;

public class Test : MonoBehaviour
{
    Vector3 startPosition = new Vector3(0, 0, 0);
    Vector3 endPosition = new Vector3(0, 0, 350);

    private void Start()
    {
        Events.onDestinationReached += OnDestinationReached;
    }

    private void OnDestinationReached(int vehicleIndex)
    {
        Debug.Log("Destination Reached" + vehicleIndex);
        if (vehicleIndex != 0)
        {
            //by removing the path, the vehicle will continue normally.
            API.RemoveVehiclePath(vehicleIndex);
        }
        else
        {
            //set a new path for the vehicle.
            API.SetDestination(vehicleIndex, GameObject.Find("DestinationObject").transform.position);
        }
    }

    private void OnDestroy()
    {
        Events.onDestinationReached -= OnDestinationReached;
    }
}

Last updated