Initialize

Description

Initializes the entire Traffic System by adding all the necessary components before starting the Traffic System.

This method should be called only once at the beginning of the scene.

Declaration

Supports multiple declarations based on the needs.

public static void Initialize(Transform activeCamera, int nrOfVehicles, VehiclePool vehiclePool)

public static void Initialize(Transform activeCamera, int nrOfVehicles, VehiclePool vehiclePool, TrafficOptions trafficOptions)

public static void Initialize(Transform[] activeCameras, int nrOfVehicles, VehiclePool carPool, TrafficOptions trafficOptions)

Parameters

NameDescription

activeCamera

Camera that follows the player or the player itself. Used to determine the line of sight for vehicle instantiations.

nrOfVehicles

The maximum number of traffic vehicles that can be active simultaneously. This value cannot be increased later during runtime.

vehiclePool

Available vehicles asset. More details about the Vehicle Pool, including its configuration can be found in Setup Guide: Vehicle Pool

trafficOptions

A TrafficOptions object used to store the initialization properties.

activeCameras

Cameras that follow the players. Utilized in multiplayer scenarios.

Example

Initializing the Traffic System inside a scene.

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()
    {
        //set initialization parameters. if not assigned the default value will be used
        TrafficOptions options = new TrafficOptions()
        {
            activeSquaresLevel = 2,
            distanceToRemove = 150,
            minDistanceToAdd = 100
        };

        API.Initialize(player, 20, vehiclePool, options);
    }
}

Last updated