Mobile Traffic System
  • Key Features
  • Demo App
  • Quick Start
  • Setup Guide
    • Prepare Scene
    • Vehicle Pool
    • Initializing Asset
    • Create a Road
    • Connect Roads
    • Priority Crossing
    • Priority Intersection
    • Traffic Lights Crossing
    • Traffic Lights Intersection
    • Setup Give-Way Waypoints
    • Roundabout Setup
    • Highway Enter Setup
    • Speed Routes Setup
    • Vehicle Routes Setup
    • Waypoint Priority Setup
    • Waypoint Setup Window
    • Waypoint Properties
    • Vehicle Implementation
    • Truck + Trailer Implementation
    • Path Finding Setup
    • Player Component
    • Change drive side
    • Debug Window
  • Complete API
    • AddDrivingAction
    • AddExcludedVehicle
    • AddExcludedVehicleToSystem
    • AddVehicle
    • AddVehicleControl
    • AddVehicleWithPath
    • AddWaypointEvent
    • ChangeLane
    • ClearPathForSpecialVehicles
    • ClearTrafficOnArea
    • DisableAreaWaypoints
    • DriveActions
    • EnableAllWaypoints
    • ExcludeVehicleFromSystem
    • GetAllVehicles
    • GetClosestWaypoint
    • GetExcludedVehicleIndex
    • GetExcludedVehicleList
    • GetPath
    • GetPriorityCrossingStopState
    • GetTrafficLightsCrossingState
    • GetVehicleComponent
    • GetVehicleIndex
    • GetVehicleSpeed
    • GetVehicleState
    • GetWaypointFromIndex
    • Initialize
    • InstantiateTrafficVehicle
    • IsInitialized
    • RemoveDrivingAction
    • RemoveVehicle
    • RemoveVehicleControl
    • RemoveVehiclePath
    • RemoveWaypointEvent
    • SetActiveSquares
    • SetCamera
    • SetCameras
    • SetDestination
    • SetEngineVolume
    • SetHazardLights
    • SetIntersectionRoadToGreen
    • SetPriorityCrossingStopState
    • SetTrafficLightsCrossingState
    • SetTrafficDensity
    • SetVehiclePath
    • StopVehicleDriving
    • TrafficOptions
    • TriggerColliderRemovedEvent
    • UpdateVehicleLights
  • Events
    • onDestinationReached
    • onVehicleAdded
    • onVehicleCrashed
    • onVehicleRemoved
    • onWaypointReached
  • Delegates
    • Building In Trigger
    • Dynamic Obstacle In Trigger
    • Modify Trigger Size
    • Player In Trigger
    • Spawn Waypoint Selector
    • Traffic Lights Behaviour
    • Vehicle Crash
  • External Tools
    • Easy Roads
    • CiDy
    • Road Constructor
  • Visual Scripting
  • FAQ
  • V2 vs V1
  • Upgrade Guide
    • Upgrade from v1.x.x to v2
    • Upgrade from v2.x.x to v2.3.x
  • Releases
  • Support
Powered by GitBook
On this page
  • Description
  • Declaration
  • Parameters
  • Returns
  • Example
  1. Complete API

GetVehicleIndex

Description

Gets the index of a vehicle GameObject.

Useful to get the list index of a specific vehicle.

Declaration

public static int GetVehicleIndex(GameObject vehicle)

Parameters

Name
Description

vehicle

The root GameObject of a traffic vehicle.

Returns

int - the list index of the vehicle (-1 = error)

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);
    }

    public void ExcludeVehicle()
    {
        //find a vehicle and exclude it from the system
        int vehicleIndex = API.GetVehicleIndex(GameObject.Find("Sedan(Clone)10"));
        if (vehicleIndex != -1)
        {
            API.ExcludeVehicleFromSystem(10);
        }
    }
}
PreviousGetVehicleComponentNextGetVehicleSpeed

Last updated 1 year ago