问题
我在使用 google play 服务创建回合制多人游戏时遇到问题>unity3D.
- PlayGamesPlatform.Activate() 成功初始化 PlayGamesPlatform。但是,它不会初始化 IPlayGamesClient 或ITurnBasedMultiplayerClient。
- CreateQuickMatch(...) 永远不会调用 OnMatchStarted(...),CreateQuickMatch(...) 中的参数。
- 每次调用 CreateQuickMatch(...) 时都会发送一个错误,“NullReferenceException:未将对象引用设置为对象 GooglePlayGames.PlayGamesPlatform.get_TurnBased()"
采取的步骤
我已研究这个在线问题。某些论坛已经指出,这个问题是由于GooglePlay API最近的变化引起的。 解决方案是将 API 降级到以前的修订版。这是不成功。
更新java和java JDK结果不成功。
用作引用的链接
https://github.com/playgameservices/play-games-plugin-for-unity https://github.com/playgameservices/play-games-plugin-for-unity/blob/master/TBMP.md
代码
// Use this for initialization
void Start ()
{
// recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;
// Activate the Google Play Games platform
PlayGamesPlatform.Activate ();
}
void OnMatchStarted (bool success, TurnBasedMatch match)
{
if (success)
{
this.gameMatch = match;
Debug.Log ("Success");
} else
{
Debug.Log ("Failed");
}
}
// Update is called once per frame
void Update ()
{
if (Input.touchCount > 0 && TouchPhase.Ended == Input.GetTouch (0).phase)
{
PlayGamesPlatform.Instance.TurnBased.CreateQuickMatch (minPlayers, maxPlayers, variant, OnMatchStarted);
}
}
最佳答案
我认为您需要先使用帐户登录才能创建房间。激活 Google Play 游戏平台后,只需添加以下代码即可。
Social.localUser.Authenticate(
(bool success) => { string loginStatus = success ? "Login successful" : "Login failed";
Debug.Log("Login status: " + loginStatus);
});
此函数将打开一个登录屏幕,您可以选择使用哪个帐户登录。函数中奇怪的参数是一个 lambda 语句,它会在身份验证过程完成时调用。在这种情况下,函数会记录 “登录状态:登录成功”
或 “登录状态:登录失败”
。
关于c# - Google Play 服务创建回合制多人游戏匹配问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24408266/