PlayerNameAssigner.cs
using Sandbox;
public sealed class PlayerNameAssigner : Component, Component.INetworkListener
{
public void OnActive( Connection connection )
{
if ( !Networking.IsHost )
return;
foreach ( var controller in Scene.GetAllComponents<ButtonMasherPlayerController>() )
{
if ( !controller.GameObject.IsValid() )
continue;
if ( controller.GameObject.Network.OwnerConnection != connection )
continue;
controller.Name = connection.DisplayName;
Log.Info( $"Assigned player name '{controller.Name}' to {controller.GameObject.Name}" );
return;
}
Log.Warning( $"Could not find spawned player object for connection {connection.DisplayName}" );
}
}