private IEnumerator SpawnSingleWave(Wave wave) { for (int i = 0; i < wave.UnitCount; i++) { foreach (SpawnPoint spawnPoint in spawnPoints) { Vector3 spawnPosition = spawnPoint.transform.position; if (spawnPoint.HasSpawnArea) { spawnPosition = spawnPoint.spawnBox.GetRandomPointInCollider(); } GameObject unit = Instantiate(wave.UnitPrefab, spawnPosition, spawnPoint.transform.rotation) as GameObject; unit.transform.SetParent(unitsTrans, true); UnitShell shell = unit.GetComponent <UnitShell>(); shell.UnitPrefabToLoad = wave.PrefabToLoad; //TODO Hardcoded way of giving orders... shell.waypoints = spawnPoint.waypoints; NetworkServer.Spawn(unit); } yield return(new WaitForSeconds(1)); } wave.isDone = true; }
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) { int playerNumber = GetPlayerNumber(conn); Debug.Log("Player joined. Assigning id: " + playerNumber); var playerObj = (GameObject)Instantiate(playerPrefab, Vector3.zero, Quaternion.identity); Player player = playerObj.GetComponent <Player>(); // -------------- Player Body -------------- // //Spawn the body of the player. Vector3 spawnPoint = new Vector3(0, 5, 11); //TODO Get the prefab from somewhere that makes sense. GameObject bodyPrefab = spawnPrefabs[0]; GameObject playerBody = Instantiate(bodyPrefab, spawnPoint, Quaternion.identity) as GameObject; BaseMotor motor = playerBody.GetComponent <BaseMotor>(); UnitShell shell = playerBody.GetComponent <UnitShell>(); //TODO Load abilities from this too? shell.UnitPrefabToLoad = "Spawnable/Characters/WarriorPrincess"; motor.Initialize(Player.MoveSpeed); NetworkServer.Spawn(playerBody); // -------------- Player -------------- // player.Initialize(playerNumber, playerBody.GetComponent <NetworkIdentity>()); _players.Add(playerNumber, player); //Spawn on network. NetworkServer.AddPlayerForConnection(conn, playerObj, playerControllerId); }