Files
survival-game/Assets/Mirror/Examples/TankTheftAuto/Scripts/TankTheftAutoNetMan.cs
2025-06-16 13:15:42 +00:00

31 lines
1023 B
C#

using Mirror.Examples.Common.Controllers.Tank;
using UnityEngine;
namespace Mirror.Examples.TankTheftAuto
{
[AddComponentMenu("")]
public class TankTheftAutoNetMan : NetworkManager
{
public override void OnServerDisconnect(NetworkConnectionToClient conn)
{
// If the client was driving a tank, destroy the cached player object
if (conn.authenticationData is GameObject player)
NetworkServer.Destroy(player);
if (conn.identity != null)
{
if (conn.identity.TryGetComponent(out TankTurretBase tankTurret))
tankTurret.playerColor = Color.black;
if (conn.identity.TryGetComponent(out TankAuthority tankAuthority))
{
tankAuthority.isControlled = false;
NetworkServer.RemovePlayerForConnection(conn, RemovePlayerOptions.KeepActive);
}
}
base.OnServerDisconnect(conn);
}
}
}