Character Select on other player's screen

Options
Hi Im having some trouble wrapping my head around character selection in multiplayer.
Goal: To display the users character on the other player's screen.
Issue: Everytime i select a character, it changes the other player's character as well.
I believe the playerID in the RPC call is the culprit. But i dont know how to fix it.
playerID = Convert.ToInt32(PhotonNetwork.player.customProperties["ID"]);
GetComponent<PhotonView>().RPC("ChosenCharacterRPC",PhotonTargets.AllBuffered, new object[]{playerID});

void SelectCharacter(GameObject Roster)
	{
		if(Roster.activeInHierarchy)
		{
			foreach (Transform child in Roster.transform)
			{
				if(child.name.Equals (curCharacter))
				{
					child.gameObject.SetActive(true);
				}
				else{
					child.gameObject.SetActive(false);
				}
			}
		}
	}

	[RPC]
	void ChosenCharacterRPC(int id)
	{
		Dictionary<int,GameObject> idCharacter = new Dictionary<int,GameObject>()
		{
			{1, Roster1},
			{2, Roster2},
			{3, Roster3},
			{4, Roster4}
		};
		SelectCharacter(idCharacter[id]);
	}

Comments

  • vadim
    Options
    You do not need to send anything player-specific in RPC call. 1st PhotonMessageInfo parameter in RPC implementation has info about sender including reference to sender's player which can be used to get ID property.
    So you can eliminate suspected playerID.

    Debug or trace the code to understand how it's working. If ChosenCharacterRPC called properly then it's not network related problem but rather failing selection logic.
  • Urob_Oros
    Options
    Thank you so much. that really helped! i finally fixed it.
    Another issue was that curCharacter in the SelectCharacter method is relative to each client.
    So that caused some funky behavior.
    THANKS AGAIN!