- Home /
Google Play ShowLeaderBoard(); won't show
I use Google Play Services in one of my android projects in Unity and have followed this tutorial: https://www.youtube.com/watch?v=5Ae8GeRmdH0, done everyting he did. Now when running the app in my phone, it shows the login screen (Google Play Services) succesfully and when pressing a button which should open the leaderboard, it doesn't work. (won't show the leaderboard)
So, I am Initializing PlayGamesPlatform and signing in at the start, and when the user touches the button, it should open Leaderboard (ShowLeaderBoardUI()).
Here's my code:
(PlayGamesScript)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SocialPlatforms;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
public class PlayGamesScript : MonoBehaviour {
// Use this for initialization
void Start () {
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
SignIn();
}
public static void SignIn()
{
Social.localUser.Authenticate(succes => { });
}
#region Leaderboards
public static void AddScoreToLeaderboard(string leaderboardId, int score)
{
Social.ReportScore(score, leaderboardId, succes => { });
}
public static void ShowLeaderboardsUI()
{
((PlayGamesPlatform)Social.Active).ShowLeaderboardUI("CgkIg5atkIMLEAIQAA");
PlayGamesPlatform.Instance.ShowLeaderboardUI(GPGSIds.leaderboard_leaderboards);
Social.ShowLeaderboardUI();
}
#endregion /Leaderboards
}
(UIManager)
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SocialPlatforms;
public class UIManager : MonoBehaviour
{
public static UIManager Instance { get; private set; }
// Use this for initialization
void Start()
{
Instance = this;
}
public void ShowLeaderboards()
{
PlayGamesScript.ShowLeaderboardsUI();
print("Show leaderboard!");
}
}
(script, that is linked to the button)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class buttonScript: MonoBehaviour, IPointerClickHandler {
// Use this for initialization
public void ShowLeaderboards()
{
UIManager.Instance.ShowLeaderboard();
print("Show leaderboard!");
}
public void OnPointerClick(PointerEventData eventData)
{
ShowLeaderboards();
}
}
Your answer
Follow this Question
Related Questions
Google play code I don't know where to use it 0 Answers
Android - Error building Player: CommandInvokationFailure: Failed to re-package resources 0 Answers
Google Play showing log in dialog but not loggin in. 0 Answers
Social.localUser.Authenticate((bool success) returns no bool 1 Answer
Google Play Services: Google Android Project or Github Plug-In? 0 Answers