private IEnumerator SpawnCore(float progress) { _enemyNumber = Number; var enemySequence = CreateEnemySequence(progress); for (int i = 0; i < Number; i++) { yield return(new WaitForSeconds(2f)); var placeholder = (GameObject)Instantiate(TankPlaceholder, EnemySpawnPoints[i % EnemySpawnPoints.Length].position, EnemySpawnPoints[i % EnemySpawnPoints.Length].rotation); NetworkServer.Spawn(placeholder); yield return(new WaitForSeconds(1f)); Destroy(placeholder); var enemy = SpawnHelper.Spawn(EnemyPrefabs[enemySequence[i]], EnemySpawnPoints[i % EnemySpawnPoints.Length], transform); NetworkServer.Spawn(enemy); _spawnedEnemies[i] = enemy; var tankLife = enemy.GetComponent <TankLife>(); tankLife.Destroyed += OnEnemyDestroyed; if (_suspended) { SuspendEnemy(enemy); } } }
private IEnumerator SpawnPlayer(int playerIndex) { if (_lifeNumbers[playerIndex] <= 0) { yield break; } var placeholder = (GameObject)Instantiate(TankPlaceholder, PlayerDatas[playerIndex].SpawnPoint.position, PlayerDatas[playerIndex].SpawnPoint.rotation); NetworkServer.Spawn(placeholder); yield return(new WaitForSeconds(1f)); Destroy(placeholder); var player = SpawnHelper.Spawn(Player, PlayerDatas[playerIndex].SpawnPoint, transform); var playerController = player.GetComponent <PlayerController>(); playerController.ApplyPlayerInfo(PlayerInfo.PlayerInfos[playerIndex]); NetworkServer.SpawnWithClientAuthority(player, PlayerInfo.PlayerInfos[playerIndex].connectionToClient); _spawnedPlayers[playerIndex] = player; var tankLife = player.GetComponent <TankLife>(); tankLife.Destroyed += (position) => OnPlayerDestroyed(playerIndex); var tankEmitter = player.GetComponent <TankEmitter>(); tankEmitter.BulletPower = _powers[playerIndex]; tankEmitter.BulletHit += () => OnBulletHit(playerIndex); var cameraSwitcher = player.GetComponent <CameraSwitcher>(); cameraSwitcher.CameraSwitched += (switchedCamera) => OnCameraSwitched(playerIndex, switchedCamera); var toolCollector = player.GetComponent <TankPlayerToolCollector>(); toolCollector.AntitankGrenadeCollected += () => OnAntitankGrenadeCollected(playerIndex); toolCollector.ClockCollected += OnClockCollected; toolCollector.HelmetCollected += () => OnHelmetCollected(playerIndex); toolCollector.LifeCollected += () => OnLifeCollected(playerIndex); toolCollector.PowerCollected += () => OnPowerCollected(playerIndex); toolCollector.SpadeCollected += OnSpadeCollected; }
public void Clear() { SpawnHelper.ClearAll(transform); }