So I've been working on a small little Multi-Player game using Photon and such. Everything is working exactly as planned, except for one thing, which is the only thing preventing me from finishing this game. Because I am new to Photon, I have been modding quill18's NetworkManager script to connect/spawn players. Because of UI reasons, I need 2 separate versions of the Player Controller to make the game work correctly. But, because there are 2 different kinds of Controllers, there have to be 2 different tags. And so on and so forth. The problem arises here:
if (playerCount == 1 || PhotonNetwork.playerList.Length == 2 && playerCount == 3) {
GameObject myPlayerGO = null;
if (playerCount == 1) {
SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length)];
myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("PlayerController1", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
standbyCamera.SetActive (false);
}
if (PhotonNetwork.playerList.Length == 2 && playerCount == 3) {
(myPlayerGO.GetComponent ("CarUserControl") as MonoBehaviour).enabled = true;
(myPlayerGO.GetComponent ("CarAudio") as MonoBehaviour).enabled = true;
(myPlayerGO.GetComponent ("CarController") as MonoBehaviour).enabled = true;
}
if (PhotonNetwork.playerList.Length <= 1) {
myPlayerGO.transform.FindChild ("Camera").gameObject.SetActive (true);
increasePlayerCount ();
}
The problem is that when I have to instantiate the first Controller, **because there are 2 if statements on the same "level"**, spawning the Controller inside one won't let me access it in the other. And setting the GameObject to null outside of both keeps it null, even when assigning it to the instantiated Controller. Is there any way I can instantiate the clone inside the first if statement, and access it from the second if statement even though they are on the same "level".
Thanks.
↧