问题描述
我试图学习如何在Unity中使用GooglePlayServices,但我遇到了一些我无法处理的问题。
所以我可以从排行榜获得所有信息并在Log中提示它,但是我不能做其他事情。这是我的代码:
IScore [] scoresFromLeaderboard = null;
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_highscore_leaderboard,
LeaderboardStart.TopScores,
10,
LeaderboardCollection.Public,
LeaderboardTimeSpan。 AllTime,
(data)=>
{
scoresFromLeaderboard = data.Scores;
Debug.Log(Scoures count:+ scoresFromLeaderboard.Length);
foreach(scoresFromLeaderboard中的IScore分数)
{
Debug.Log(Score:+ score.formattedValue);
}
}
);
当我尝试添加变量并为其写入一些分数时,没有任何事情发生。另外,当我尝试做这个foreach:
foreach(在scoresFromLeaderboard中的IScore得分)
{
Debug。日志(Score:+ score.formattedValue);
}
后PlayGamePlatform.Instance.LoadScore {..}我不明白日志...
在官方文档中,它看起来像是从排行榜保存信息是可能的,但是当我尝试这样做时,我没有在变量中获取任何字符串(来自Google Play插件git的代码):
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_leaders_in_smoketesting,
LeaderboardStart.PlayerCentered,
100,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(data)=>
{
mStatus =排行榜数据有效:+ data.Valid;
mStatus + =\\\
approx:+ data.ApproximateCount +have+ data.Scores.Length;
});
有人知道我做错了什么?
试图在这里回答一个较老的问题,但是我自己也遇到了完全相同的问题。这是我的解决方案,希望它可以帮助其他人。
我将GPGSIds.leaderboard_leaders_in_smoketesting作为字符串(abcd123)更改为我的实际排行榜ID。 >
另外,请尝试使用LeaderboardCollection.Social而不是.Public。查看是否返回数据。
通过以上操作,我可以看到Xcode日志中返回的数据。
但我必须承认,我也遇到了很多挑战。最令人讨厌的是,你无法在Unity中测试这些东西,你必须每次在设备上测试,这是一个巨大的痛苦。
I'm trying to learn how to use GooglePlayServices in Unity but i have a little problem that i can't handle.So i can get all information from leaderboard and prompt it in Log but i can't do enything else. Here is my code:
IScore[] scoresFromLeaderboard = null;
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_highscore_leaderboard,
LeaderboardStart.TopScores,
10,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(data) =>
{
scoresFromLeaderboard = data.Scores;
Debug.Log("Scoures count: " + scoresFromLeaderboard.Length);
foreach(IScore score in scoresFromLeaderboard)
{
Debug.Log("Score: " + score.formattedValue);
}
}
);
When i try to add variable and write some score to it there's nothing happen. Also when i try do this foreach:
foreach(IScore score in scoresFromLeaderboard)
{
Debug.Log("Score: " + score.formattedValue);
}
after PlayGamePlatform.Instance.LoadScore{..} i don't get and Logs...
In official documentation it's look like save information from leaderboard is possible, but when i try to do like this i don't get any string in variable(code from google play plugin git):
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_leaders_in_smoketesting,
LeaderboardStart.PlayerCentered,
100,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(data) =>
{
mStatus = "Leaderboard data valid: " + data.Valid;
mStatus += "\n approx:" +data.ApproximateCount + " have " + data.Scores.Length;
});
Somebody know what i am doing wrong?
Trying to answer an older question here, but ran into exact same problem myself. Here's my solution so far, hope it helps others.
I changed this: GPGSIds.leaderboard_leaders_in_smoketesting to my actual leaderboard ID as a string ("abcd123").
Also, try to use LeaderboardCollection.Social instead of .Public. See if that returns data.
By doing the above, I see data returned in the Xcode logs.
But I must admit, I am running into quite a few challenges as well. Most annoying is that you can't test any of this stuff in Unity itself, you have to test on the device each time, which is a massive pain.
这篇关于Unity3d,GooglePlayServices和PlayGamesPlatform.Instance.LoadScores - 无法将值写入变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!