> For the complete documentation index, see [llms.txt](https://gley.gitbook.io/mobile-traffic-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gley.gitbook.io/mobile-traffic-system/events/onvehiclecrashed.md).

# onVehicleCrashed

## Description

Triggered when a vehicle crashes into another object.&#x20;

<table><thead><tr><th width="220">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>vehicleIndex</strong></td><td>The index of the vehicle that crashed</td></tr><tr><td><strong>obstacleType</strong></td><td>The type of obstacle that was hit (Road, StaticObject, DynamicObject, TrafficVehicle, Player, Other).</td></tr><tr><td><strong>other</strong></td><td>The other collider that was hit.</td></tr></tbody></table>

## Example

```csharp
    void Start()
    {
        API.Initialize(player, 20, vehiclePool);
        Events.onVehicleCrashed += VehicleCrashed;
    }

    private void VehicleCrashed(int vehicleIndex, ObstacleTypes obstacleType, Collider other)
    {
        switch (obstacleType)
        {
            case ObstacleTypes.Player:
                //player was hit, do something
                if(other.name == "Player1")
                {
                    Debug.Log("Player 1 was hit");
                }
                break;
            case ObstacleTypes.DynamicObject:
                //a moving object was hit
                break;

                //Continue for other types of obstacle
        }
    }

    private void OnDestroy()
    {
        Events.onVehicleCrashed -= VehicleCrashed;
    }
```
