A trigger volume component that respawns any Car entering it. On trigger enter it finds a Car component on the collider or its parent and calls Respawn.Respawn() if present.
using Machines.Player;
namespace Machines.Race;
/// <summary>
/// Trigger volume that respawns any car entering it; place below or around out-of-bounds areas.
/// </summary>
public sealed class KillVolume : Component, Component.ITriggerListener
{
public void OnTriggerEnter( Collider other )
{
var car = other.GameObject.GetComponent<Car>();
if ( !car.IsValid() )
car = other.GameObject.Parent?.GetComponent<Car>();
if ( !car.IsValid() )
return;
// Respawn() self-gates to the owning machine, safe to call from any client.
car.Respawn?.Respawn();
}
public void OnTriggerExit( Collider other ) { }
}