public override void RestartMatch() { RaceTimer = MatchTimer; PreRaceTimer = PreMatchTimer; PostRaceTimer = PostMatchTimer; PreStormTimer = OriginalPreStormTimer; WinCondition = false; LoseCondition = false; StormPosition = OriginalStormPosition; StormRotation = OriginalStormRotation; Players.ForEach(player => { player.playerName = RandomUserNames.GetUsername(); player.vehicleColor = RandomUserNames.GetColor(); }); RespawnAll(); ClearAllVehicles(); ClearAllItems(); SpawnEverything(); MatchBegun = false; SetMatchBegun(false); ToggleEndOfRaceUI(false); RpcToggleEndOfRaceUI(false); }
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader reader) { base.OnServerAddPlayer(conn, playerControllerId); //GET MESSAGE FROM CLIENT FOR WHICH PLAYER PREFAB TO SPAWN if (reader != null) { var message_stream = reader.ReadMessage <IntegerMessage>(); playerIndex = message_stream.value; } //playerIndex = Random.Range(0, PlayerPrefabs.Count); short controller_id = 0; var spawn = GetStartPosition(); var spawn_player = Instantiate(PlayerPrefabs[playerIndex], spawn.position, spawn.rotation); var playerBehaviour = spawn_player.GetComponent <PlayerBehaviour>(); var playerDress = spawn_player.GetComponent <PlayerDressBehaviour>(); playerDress.SkinColor = RandomUserNames.GetColor(); playerDress.ShirtColor = RandomUserNames.GetColor(); playerDress.PantsColor = RandomUserNames.GetColor(); playerBehaviour.playerName = RandomUserNames.GetUsername(); playerBehaviour.vehicleColor = RandomUserNames.GetColor(); NetworkServer.AddPlayerForConnection(conn, spawn_player, controller_id); gamemode_manager.gamemode.Players.Add(playerBehaviour); gamemode_manager.gamemode.RestartPreMatchTimer(); #region OLD //allConnections.Add(conn); ////ADD THIS PLAYER TO THE GAMEMODE'S PLAYER LIST //var allPlayers = FindObjectsOfType<PlayerBehaviour>().ToList(); //allPlayers.ForEach(player => //{ // var playerNetIdentity = player.GetComponent<NetworkIdentity>(); // var playerConnection = playerNetIdentity.connectionToClient.connectionId; // if(playerConnection == conn.connectionId) // { // player.playerName = RandomUserNames.GetUsername(); // player.vehicleColor = RandomUserNames.GetColor(); // //ADD THIS PLAYER TO THE GAMEMODES LIST OF PLAYERS // gamemode_manager.gamemode.Players.Add(player); // } //}); #endregion }
//public Text PLAYERNAME; //public PlayerInfo Info; ////REFRENCE TO THE PREMATCH TIMER //public InGameNetworkBehaviour net_companion; //public GamemodeManager gamemode_manager; public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) { base.OnServerAddPlayer(conn, playerControllerId); //ADD THIS PLAYER TO THE GAMEMODE'S PLAYER LIST var allPlayers = FindObjectsOfType <PlayerBehaviour>().ToList(); allPlayers.ForEach(player => { var playerNetIdentity = player.GetComponent <NetworkIdentity>(); var playerConnection = playerNetIdentity.connectionToClient.connectionId; if (playerConnection == conn.connectionId) { player.playerName = RandomUserNames.GetUsername(); player.vehicleColor = RandomUserNames.GetColor(); } }); }