// A new level has been loaded void OnLevelWasLoaded(int level) { //Gathers the players' identities var identities = GetComponents <PlayerIdentity>().Take(GameBuilder.kMaxPlayerCount); //Create the ships at the spawn points int player_id = 0; GameObject[] spawn_points = GameObject.FindGameObjectsWithTag(Tags.SpawnPoint); var factory = GameObjectFactory.Instance; GameObject player; foreach (PlayerIdentity identity in identities) { player = factory.Instantiate("Prefabs/Ships/" + identity.ShipName, spawn_points[player_id].transform.position, Quaternion.identity) as GameObject; identity.CopyTo(player.GetComponent <PlayerIdentity>()); player.GetComponent <GameIdentity>().Id = player_id; //TODO: find a better way if (!identity.IsHuman) { player.AddComponent <PlayerAI>(); } else { GameObject.FindGameObjectWithTag(Tags.MainCamera).GetComponent <CameraMovement>().LookAt(player); } ++player_id; //Destroy(identity); } //Loads the Game prefab and enables the Game component var game_obj = GameObjectFactory.Instance.Instantiate("Prefabs/Game", Vector3.zero, Quaternion.identity); var game = game_obj.GetComponent <Game>(); game.GameMode = GameModes.Resolve(GetComponent <GameBuilder>().GameMode); game.enabled = true; }
protected override void ArenaLoaded(int id) { if (IsArenaLoading) { ready_players_.Add(id); if (ready_players_.Count == player_ids_.Count) { for (int i = 0; i < kMaxViewId; i++) { networkView.RPC("RPCSendViewID", RPCMode.All); } //Everyone loaded the arena, start intializing ready_players_.Clear(); //Create the game var game_resource = Resources.Load("Prefabs/Game"); GameObject game = Network.Instantiate(game_resource, Vector3.zero, Quaternion.identity, 0) as GameObject; //Set the game mode and the arena game.networkView.RPC("RPCSetGame", RPCMode.All, GameModes.Resolve(GetComponent <GameBuilder>().GameMode)); //Create the ships GameObject[] spawn_points = GameObject.FindGameObjectsWithTag(Tags.SpawnPoint); foreach (KeyValuePair <NetworkPlayer, int> player_id in player_ids_) { if (!player_id.Key.Equals(Network.player)) { networkView.RPC("RPCCreatePlayer", player_id.Key, spawn_points[player_id.Value].transform.position); } else { RPCCreatePlayer(spawn_points[player_id.Value].transform.position); } } } } }