Photon team assignment

So I'm trying to create a moba but can't assign the team properly in the champ select. Basically the last player to join sees everyone as it should be. But everyone else doesn't see the last player. When I run a debug on the last player's client he has a team assigned. But when I run the debug on the other clients the last player's team is null. No ideea why... Here is my code:

void OnJoinedRoom(){
		Debug.Log(PhotonNetwork.playerList.Length);
		Debug.Log(PhotonNetwork.room.MaxPlayers);
		if(PhotonNetwork.playerList.Length <= PhotonNetwork.room.MaxPlayers/2){
			Debug.Log("Assigned Red");
			PhotonNetwork.player.SetCustomProperties(new Hashtable() {{"team","red"}});
		}else{
			Debug.Log("Assigned Blue");
			PhotonNetwork.player.SetCustomProperties(new Hashtable() {{"team","blue"}});
		}
		StartCoroutine(Await(1f));
		joined = true;
	}


void Update(){
		if(joined && PhotonNetwork.playerList.Length == 2 && !doOnce){
			Debug.Log("Start");
			doOnce=true;
			//this.GetComponent<PhotonView>().RPC ("StartGame", PhotonTargets.All);
			StartCoroutine(Await(3f));
			StartGame();
		}
	}


void StartGame(){
		inRoomPanelGo.SetActive(false);
		champSelectGo.SetActive(true);
		foreach(PhotonPlayer pl in PhotonNetwork.playerList){
			Debug.Log(pl.NickName + " IS HERE " + "AND HE IS TEAM " + pl.CustomProperties["team"]);
			if((string)pl.CustomProperties["team"]=="blue"){
				Debug.Log(pl.NickName + "   " + pl.CustomProperties["team"]);
				GameObject spawnedCsPlayerBl = Instantiate(csPlayerPrefabBlue, Vector3.zero, Quaternion.identity)
				 as GameObject;
				spawnedCsPlayerBl.transform.SetParent(blueContainer, false);
				spawnedCsPlayerBl.transform.GetChild(0).GetComponent<Text>().text=pl.NickName;
			}else if((string)pl.CustomProperties["team"]=="red"){
				Debug.Log(pl.NickName + "   " + pl.CustomProperties["team"]);
				GameObject spawnedCsPlayerRd = Instantiate(csPlayerPrefabRed, Vector3.zero, Quaternion.identity)
				 as GameObject;
				spawnedCsPlayerRd.transform.SetParent(redContainer, false);
				spawnedCsPlayerRd.transform.GetChild(0).GetComponent<Text>().text=pl.NickName;
			}
		}
	}

Comments

  • KurtavKurtav
    edited June 18
    So "StartGame()" at you RPC function or usual function?
    if usual function , You create a network player and not an ordinary player - PhotonNetwork.Instantiate and other players do not execute these lines
    spawnedCsPlayerBl.transform.SetParent(blueContainer, false);
    spawnedCsPlayerRd.transform.SetParent(redContainer, false);
  • SphadesSphades
    edited June 18
    Hey Kurtav. Thanks for the fast answer.
    StartGame() is a normal function. I'll try to do that and see if it works. Until then here is a sketch of what happens and the debugs.


    (Link : http://i.imgur.com/o0kOGWW.png )
Sign In or Register to comment.