ChangeLane
Description
Forces a traffic vehicle to change the lane in the indicated direction. The vehicle will make sure the lane is free before changing it.
Declaration
public static void ChangeLane(bool active, int vehicleIndex, RoadSide side = RoadSide.Any)Parameters
Name
Description
active
If true the ChangeLane action will be added to the vehicle, otherwise it will be removed.
vehicleIndex
The index of the vehicle.
side
The road side for changing the lane.
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);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
//move to the right lane if exists
API.ChangeLane(true, 0, RoadSide.Right);
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
//move to the left lane if exists
API.ChangeLane(true, 0, RoadSide.Left);
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
//stop changing lanes
API.ChangeLane(false, 0);
}
}
}
Last updated