Sending player name photon

Having some issues receiving player names over photon network.

Not got a problem if i am the host i see both the hosts name and the opponents name, The problem comes when i join as the second player i see his name in both name slots not the hosts.

my code is below:

Player1 Code:

public UILabel playerName;

	// Update is called once per frame
	[PunRPC]
	void Update () {

		if (playerName != null) {
			playerName.text = global.username;

		}
	}
}

Player2 Code:

public UILabel player2Name;
	
	// Update is called once per frame
	[PunRPC]
	void Update () {
			
			if (player2Name != null) {
			player2Name.text = PlayerPrefs.GetString("SAVED_username", "");
		}
	}
}

Tried a few things but still the second player shows its name in both slots. Any solutions would be greatly appreciated thanks.

You don’t have to send the name via RPC. It’s built-in to PUN, so synchronize the PhotonNetwork.playerName, if you set it.

PhotonNetwork.otherPlayers is a list of other players and each contains the playerName the remote player set.

Saving the player name in the preferences however, is a good idea :slight_smile: