简体   繁体   中英

Get opponent user name google play games real time in unity

I'm working on an app, it's a simple Realtime Multiplayer game using Google play games asset in Unity.

It's a 1 vs 1 game.

I would like to have access to the opponent user name.

So i can display it in the beginning of a game (just after Random Match, or Match with invitation is created).

I can access to the current player user name with this:

string PlayerUserName = PlayGamesPlatform.Instance.RealTime.GetSelf().DisplayName;

I tried this :

string PlayerUserName = PlayGamesPlatform.Instance.RealTime.GetSelf().ParticipantId;

It returns a huge line of random characters, and i think it's the own player id.

Is it possible to do that?

You may refer with this thread which stated that if you using Google Play Games plugin for Unity plugin it allows you to access the Google Play Games API through Unity's social interface . You can use Social.LoadUsers() to load the player profile. Remember that the contents of the player profile are subject to privacy settings of the players. Then use user.userName to get the username based on their userID .

its too late to replay .but it may help others......

string current_player_id = PlayGamesPlatform.Instance.RealTime.GetSelf ().ParticipantId;
Participant p = PlayGamesPlatform.Instance.RealTime.GetParticipant (current_player_id);

List participants = PlayGamesPlatform.Instance.RealTime.GetConnectedParticipants();
string player1_id = participants [0].ParticipantId;
Participant p1 = PlayGamesPlatform.Instance.RealTime.GetParticipant (player1_id);
string player2_id = participants [1].ParticipantId;
Participant p1 = PlayGamesPlatform.Instance.RealTime.GetParticipant (player2_id);
if (p1.ParticipantId== p.ParticipantId) {
 opponentname.text = p2.DisplayName;
} else if (p2.ParticipantId== p.ParticipantId)
{
PlayerName.text = p1.DisplayName;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM