Unity Google Play服务
问题描述:
我正试图让Google Play服务进入我开发的游戏。这是我在主屏幕上的脚本。我根本没有回应。我尝试了所有不同的SHA1代码,我不确定哪里出了问题。有任何想法吗???Unity Google Play服务
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using UnityEngine.UI;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
public class GPS_Main : MonoBehaviour {
private bool IsConnectedToGoogleServices;
public Text SignIn;
private void Awake()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
}
// Use this for initialization
void Start() {
LogIn();
}
// Update is called once per frame
void Update() {
}
void LogIn()
{
Social.localUser.Authenticate(success => { });
}
public bool ConnectToGoogleServices()
{
if (!IsConnectedToGoogleServices)
{
Social.localUser.Authenticate((bool success) =>
{
IsConnectedToGoogleServices = success;
});
}
return IsConnectedToGoogleServices;
}
public static void ToAchievementUI()
{
if (Social.localUser.authenticated)
{
Social.ShowAchievementsUI();
}
else
{
Debug.Log("Not authenticated");
}
}
}
这确实是一件令人讨厌的事件。我经历了很多视频和书籍,试图找到正确的解决方案。
答
有很多事情导致这种情况发生,找到它的最好办法是尝试连接手机,然后使用adb logcat
来查看是什么导致了问题。
此外,我发现了一个小虫子在你的函数ConnectToGoogleServices
:
public bool ConnectToGoogleServices()
{
if (!IsConnectedToGoogleServices)
{
Social.localUser.Authenticate((bool success) =>
{
IsConnectedToGoogleServices = success;
});
}
return IsConnectedToGoogleServices;
}
此功能总是返回IsConnectedToGoogleServices
初始状态。