GetWaypointFromIndex

Description

Returns the Waypoint object for a given waypoint index.

Declaration

public static Waypoint GetWaypointFromIndex(int waypointIndex)

Parameters

NameDescription

waypointIndex

The index of the waypoint.

Returns

Waypoint - The Waypoint object at the index position inside the waypoint list.

Example

using Gley.TrafficSystem;
using Gley.TrafficSystem.Internal;
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);
    }

    public void CreatePath()
    {
        //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);

        foreach (int pathIndex in path)
        {
            Waypoint waypoint = API.GetWaypointFromIndex(pathIndex);
            Debug.Log(waypoint.name + " " + waypoint.position);
        }
    }
}

Last updated