Vehicle Crash

Description

Controls how the traffic vehicle reacts when it crashes into something.

Declaration

public delegate void VehicleCrash(int vehicleIndex, ObstacleTypes obstacleType, Collider other);

Parameters

NameDescription

vehicleIndex

The index of the vehicle that saw the building.

obstacleType

The type of the commiding object.

other

The collider of the coliding object.

Set Method

 public static void SetVehicleCrash(VehicleCrash vehicleCrashDelegate)

Example

using Gley.TrafficSystem;
using UnityEngine;

public class Test : MonoBehaviour
{
    private void Start()
    {
        Delegates.SetVehicleCrash(MyVehicleCrashBehaviour);
    }

    public static void MyVehicleCrashBehaviour(int vehicleIndex, ObstacleTypes obstacleType, Collider other)
    {
        switch (obstacleType)
        {
            case ObstacleTypes.Player:
                //stop
                API.AddDrivingAction(vehicleIndex, DriveActions.StopTemp, false);
                break;
            case ObstacleTypes.Road:
                //ignore
                break;
            case ObstacleTypes.TrafficVehicle:
                //do some special action
                API.AddDrivingAction(vehicleIndex, SomeComplexSction(vehicleIndex, other), false);
                break;
            default:
                //by default stop
                API.AddDrivingAction(vehicleIndex, DriveActions.StopTemp, false);
                break;
        }
    }
}

Default delegate implementation can be found inside DefaultDelegates.cs

Last updated