Hi Unity,
I am stuck and need some help please
I am trying to display all player’s names that are in a matchmaking room together. I am using RPC’s to do this.
So I have a List<> of strings called playerNames. When a player joins the game, the send an RPC called "ReceiveJoinedPlayerNames(string pName). This is sent in the start() method.
It is sent as others.buffered.
Now that method looks like this:
[RPC]
void ReceiveJoinedPlayerNames(string pName)
{
playerNames.Add(pName);
}
So essentially, it adds that player’s name to the player list. The player’s own name is also added to that list in the start method.
The first person to join the game sees both his name and the player that joined, the second player only sees his own name.
Its as if he never receives the buffered RPC that was sent. I am not sure why he doesnt receive it, any thoughts? Here is pretty much the full code:
// Use this for initialization
void Start ()
{
//send everyone your name
photonView.RPC("ReceiveJoinedPlayerNames",PhotonTargets.OthersBuffered, PhotonNetwork.playerName);
//add your name to your own player list
playerNames.Add(PhotonNetwork.playerName);
}
void Update ()
{
UpdateTimer();
UpdatePlayerList();
}
void UpdatePlayerList()
{
for(int cnt = 0; cnt < playersText.Length; cnt++)
{
//either show a player or open
if(cnt < playerNames.Count) // if on first past there is a player in here
{
//show their name
playersText[cnt].GetComponent<UILabel>().text = playerNames[cnt];
}
}
}
[RPC]
void ReceiveJoinedPlayerNames(string pName)
{
playerNames.Add(pName);
}