//Waits for clients, then syncs playercount, and spawns npcs private IEnumerator waitForClients() { // Wait for all clients to tell the server their data file loading state. yield return(new WaitForSeconds(1.0f)); NetworkPlayerSelect lobbyManager = Object.FindObjectOfType <NetworkPlayerSelect>(); int playerCount = lobbyManager.numPlayers; while (!WorldData.ready || !GameInfo.playersReady || !lobbyManager.IsDataLoadingComplete()) { yield return(0); } string[] npcPrefabNames = { "CatNPC", "DogNPC", "EagleNPC", "WhaleNPC", "ChikenNPC" }; List <GameObject> npcs = new List <GameObject>(); foreach (string name in npcPrefabNames) { npcs.Add(Resources.Load <GameObject>("Prefabs/NPCs/" + name)); } for (int i = 0; i < _npcCount; i++) { this.CmdSpawnNPC(npcs[Random.Range(0, npcs.Count)], i % 5); } }
// Use this for initialization void Start() { if (this.isServer) { NetworkPlayerSelect lobby = Object.FindObjectOfType <NetworkPlayerSelect>(); this.gamemode = lobby.getGameMode(); this.map = lobby.getMap(); this.numPlayers = lobby.numPlayers; init(gamemode, map, numPlayers); } else { getServerData(); } }
//Waits for clients, then syncs playercount, and spawns npcs private IEnumerator waitForClients() { if (this.isServer) { // Wait for all clients to tell the server their data file loading state. yield return(new WaitForSeconds(1.0f)); NetworkPlayerSelect lobbyManager = UnityEngine.Object.FindObjectOfType <NetworkPlayerSelect>(); // When this is true, all clients are connected and in the game scene. // Also all clients have completed loading their data files. while (!GameInfo.playersReady || !lobbyManager.IsDataLoadingComplete()) { yield return(0); } this._rngSeed = UnityEngine.Random.Range(0, 9999999); } }