Anil
Anil

Reputation: 25

Google Play Services Unity Plugin not Show Leaderboard

I am building a game for Android with Unity 5, and I have imported this plugin

But it's not working properly I followed this tutorial :

When I try to post or show leaderboard , it does not show anything .It does not even throw any error. Sign-in and out are working properly.Please help

Code :

public void LogIn ()
{
    Social.localUser.Authenticate ((bool success) =>
    {
        if (success) {
            Debug.Log ("Login Sucess");
        } else {
            Debug.Log ("Login failed");
        }
    });
}

public void LogOut ()
{
    PlayGamesPlatform.Instance.SignOut ();
}

public void Post ()
{

    if (Social.localUser.authenticated) {
        Social.ReportScore (5000, LeaderbordId, (bool success) =>
        {
            if (success) {
                ((PlayGamesPlatform)Social.Active).ShowLeaderboardUI (LeaderbordId);
            } else {
                Debug.Log ("Add Score Fail");
            }
        });
    } 
}

public void ShowLeader ()
{

    Social.ShowLeaderboardUI ();
}

Upvotes: 1

Views: 6884

Answers (2)

Fahad
Fahad

Reputation: 2053

You must be running your game inside editor , You need to run your game in an actual device or perhaps an emulator ( with a gmail account ... those are rare)

Here is the thing ... open a console , and type this

adb logcat 

or you can narrow the result by filtering only logs from unity

adb logcat -s Unity

Open your game , look at at the console If you get

ShowAchievementsUI not implemented

or

ShowLeaderboardsUI not implemented

That only means that you are using the default configurations (The unity one) I suggest you replace the defaults with google play's

The default configuration needs to be replaced with a custom configuration

    using GooglePlayGames;
    using GooglePlayGames.BasicApi;
    using UnityEngine.SocialPlatforms;

    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
        // enables saving game progress.
        .EnableSavedGames()
        // registers a callback to handle game invitations received while the game is not running.
        .WithInvitationDelegate(<callback method>)
        // registers a callback for turn based match notifications received while the
        // game is not running.
        .WithMatchDelegate(<callback method>)
        .Build();

    PlayGamesPlatform.InitializeInstance(config);
    // recommended for debugging:
    PlayGamesPlatform.DebugLogEnabled = true;
    // Activate the Google Play Games platform
    PlayGamesPlatform.Activate();

Any errors will now be shown in the console, actually you dont need all of that of it to work , you only need these

PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();

for logging the errors , Then you can authenticate :)

If you open it and suddenly it crashes , it means that you have a problem in your manifest file

you probably going to need this if you using an older version (This get added automatically if you are using the latest version)

<application ... >
...
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
....
</application>   

Make sure you update google play services to the latest one via the SDK Manager , that way you can avoid unpleasant situations

Cheers.

Upvotes: 0

Vitor Figueredo
Vitor Figueredo

Reputation: 629

I'm not sure if i got what you want. I think you are trying to open leaderboards everytime you post a score. I'll change your script to make it easier to understand.

When you are using Google Play Services Pluggin you need a few things to get started. Make sure you have this. On the top of the script you'll write:

using GooglePlayGames;
using UnityEngine.SocialPlatforms;

Then you'll need to add this to your start function:

void Start(){
    PlayGamesPlatform.Activate();
}

It's easier if you make an function just to show your leaderboards, like your last function for example:

public void ShowLB(){
    ((PlayGamesPlatform) Social.Active).ShowLeaderboardUI("YOUR_LEADERBOARDS_ID_HERE");
}

Then your Post () function would be like this:

public void Post (){

    if (Social.localUser.authenticated) {
        Social.ReportScore (5000, LeaderbordId, (bool success) =>
        {
            if (success) {
                ShowLB ();
            } else {
                Debug.Log ("Add Score Fail");
            }
        });
    } 
}

And it seems like in your last function you might want to do this:

public void ShowAchievs(){
    Social.ShowAchievementsUI ();
}

Otherwise it should be like this:

public void ShowLB(){
    ((PlayGamesPlatform) Social.Active).ShowLeaderboardUI("YOUR_LEADERBOARDS_ID_HERE");
}

But it's WAY MORE EASY if you just use your post function after a trigger, like the end of the game, and use something else to show your LB. Like a click on a button or something.

I don't know that's what you wanted.

Upvotes: 2

Related Questions