public void StartGame() { if (startable) { NetworkPlayer localPlayer = GameObject.Find("local").GetComponent <NetworkPlayer>(); localPlayer.SetupNames = true; NetworkManager.Instance.SendConnectMessage((int)localPlayer.netId.Value, playerData.GetCompanyName()); SceneManager.LoadScene("MainGameUIScene", LoadSceneMode.Single); } }
// Start is called before the first frame update void Start() { try { // Load player data from company creation playerData = GameObject.Find("PlayerData").GetComponent <PersistentPlayerData>(); if (playerData.GetCompanyName() == null) { // If company creation scene is loaded when running main scene, restart this.RestartGame(); return; } // Find network stuff networkManager = GameObject.Find("NetworkManager").GetComponent <NetworkManager>(); networkPlayers = networkManager.getPlayerList(); Debug.Log("Player count: " + networkPlayers.Count); //foreach (NetworkPlayer player in networkPlayers) { // Debug.Log(player + // " isClient: " + player.gameObject.GetComponent<NetworkIdentity>().isClient + // " " + player.gameObject.GetComponent<NetworkIdentity>().netId.ToString() // ); //} foreach (NetworkPlayer player in networkPlayers) { Debug.Log(player + " isClient: " + player.isClient + " isServer: " + player.isServer + " isLocalPlayer: " + player.isLocalPlayer + " " + player.gameObject.GetComponent <NetworkIdentity>().netId.ToString() + " " + player.netId.ToString() ); } } catch (NullReferenceException) { // If player data is missing we are probably loading from the wrong place this.RestartGame(); return; } /* Load game logic scenes */ //SceneManager.LoadScene("GameLogicScene", LoadSceneMode.Additive); SceneManager.LoadScene("CardsLogicScene", LoadSceneMode.Additive); /* Instantiate other company info cards */ GameObject companyContainer = GameObject.Find("OtherCompaniesPanel"); for (int i = 0; i < networkPlayers.Count; i++) { if (networkPlayers[i].isLocalPlayer) { ownNetworkPlayer = networkPlayers[i]; } } for (int i = 0; i < networkPlayers.Count; i++) { if (!networkPlayers[i].isLocalPlayer) { CompanyModel company = new CompanyModel(networkPlayers[i]); company.localCompany = ownNetworkPlayer; GameObject newInstance = Instantiate(companyPrefab, companyContainer.transform, false); newInstance.transform.SetParent(companyContainer.transform, false); UICompanyController cc = newInstance.GetComponent <UICompanyController>(); networkPlayers[i].uiCompanyController = cc; cc.SetCompanyModel(company); } } /* Put info in own company info panel */ companyStatus = GameObject.Find("CompanyStatusPanel").GetComponent <UICompanyController>(); ownNetworkPlayer.companyName = playerData.GetCompanyName(); ownNetworkPlayer.uiCompanyController = companyStatus; CompanyModel localCompany = new CompanyModel(ownNetworkPlayer); localCompany.localCompany = ownNetworkPlayer; companyStatus.SetCompanyModel(localCompany); player = GameObject.Find("Player"); ownNetworkPlayer.OnPlayerDoneCreateCompany(); //// TEST DATA //////// //TestData(); /////////////////////// }