Why isn't this script posting the score to Google Play Leaderboards?
Hi there!
I made this script to post the score to my leaderboard, but for some reason the leaderboard UI opens but it says "No one in your circles has played (my project)". Why isn't the score posting?
using UnityEngine;
using System.Collections;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
public class PlayGames: MonoBehaviour {
// Use this for initialization
void Start ()
{
Social.localUser.Authenticate((bool success) => {
// handle success or failure
});
Social.ReportScore (54321, "CgXXXX3m-XXXXAI", (bool success) => {
});
Social.ShowLeaderboardUI();
}
}
Leaderboard ID partially hidden (so no one posts fake scores). Thank you so much!
Answer by DroidifyDevs · Feb 09, 2016 at 02:28 AM
YES, I FINALLY GOT IT
This is what I did, I'm sure some of this is redundant: 1: When to the Google Developer console and loaded up my APK as a Beta game 2: Went into the Google Developer console > Google services and created all new leaderboards. 3: Changed my game's package name (com.DroidifyDevs.RocketTest) 4: Reinstalled Google Play pugin 5: Used this script:
using GooglePlayGames;
using UnityEngine;
using System.Collections;
public class PlayGamesWorksinRT2 : MonoBehaviour {
// Use this for initialization
void Start() {
PlayGamesPlatform.Activate();
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
GoogleTest();
PlayGamesPlatform.Activate();
Social.ShowLeaderboardUI();
}
else
Debug.Log("Auth wrong :(");
});
PlayGamesPlatform.Activate();
Social.ReportScore(50, "CgxxxxxxxxxxxBQ", (bool success) => {
});
}
// Update is called once per frame
void Update () {
}
void GoogleTest() //Call GameOver whenever your game is... over, let say .. when your player got N amount of points or N amount of damage...
{
//if (actualScore >= 5000)
// winText.text = "Good Job";
Debug.Log("Activated, Auth begins");
PlayGamesPlatform.Activate();
Social.ReportScore(50, "CgXXXXXXXXXXBQ", (bool success) => {
});
PlayGamesPlatform.Activate();
Social.ShowLeaderboardUI();
}
}
So basically I reset anything that could be reset. Feeling damn proud of myself :)
Good for you, but I'm still struggling with the same problem and can't really figure out what the actual cause is. Were you able to deter$$anonymous$$e the exact thing that was causing the problem? Would appreciate some help. Thx! :)
"You should only call PlayGamesPlatform.Activate once in your application." https://github.com/playgameservices/play-games-plugin-for-unity/blob/master/READ$$anonymous$$$$anonymous$$md
Answer by corn · Feb 07, 2016 at 11:06 AM
You need to initialize PlayGamesPlatform before authenticating.
GooglePlayGames.PlayGamesPlatform.Activate();
Social.localUser.Authenticate((bool success) => {
Debug.LogFormat("Authentication success : {0}", success);
});
@corn Thanks for the hep. Unfortunately it opens the leaderboard but doesn't post any score at all. Here's the updated script:
using UnityEngine;
using System.Collections;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
public class PlayGames: $$anonymous$$onoBehaviour {
// Use this for initialization
void Start ()
{
GooglePlayGames.PlayGamesPlatform.Activate ();
Social.localUser.Authenticate((bool success) => {
// handle success or failure
});
Social.ReportScore (54321, "CXXXXXm-mXXXXXI", (bool success) => {
});
Social.Show$$anonymous$$erboardUI();
}
}
I've even created other leaderboards but to no avail.
@putin2001 That's because Authenticate and ReportScore are asynchronous, they need callbacks. In your program, Social.ReportScore is executed before the authentication result is even received, it can't work.
Just report the score after authentication has succeeded.
void Start()
{
GooglePlayGames.PlayGamesPlatform.Activate();
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
Social.ReportScore(54321, "CXXXXXm-mXXXXXI", (bool reportScoreSuccess) =>
{
if (reportScoreSuccess)
{
Social.Show$$anonymous$$erboardUI();
}
else
{
Debug.Log("Score reporting failure");
}
});
}
else
{
Debug.Log("Authentication failure");
}
});
}
Now that's just a quick fix. It'd be much more convenient for your tests to have a public ReportScore function that'd you call with a GUI button.
@corn I tried that script, still no avail. Do I need to have the google play services linked properly to the latest AP$$anonymous$$ of my app? I guess I'll find out in a few hours as I'm waiting for Google to finish processing my changes. What is wierd is the script shows "Google play Games" then asks me what account to use, then asks if I agree with the app's use of my info, then that's it, it doesn't even show the log-in icon on the top of the screen (which normally would show up and show your account picture along with gamer level). So I'm thinking that it isn't properly logging in. In a previous project I actually got the leaderboards to work with this script:
using GooglePlayGames;
using UnityEngine;
using System.Collections;
public class PlayGamesWorksinRT2 : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start() {
PlayGamesPlatform.Activate();
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
GoogleTest();
PlayGamesPlatform.Activate();
Social.Show$$anonymous$$erboardUI();
}
else
Debug.Log("Auth wrong :(");
});
}
// Update is called once per frame
void Update () {
}
void GoogleTest() //Call GameOver whenever your game is... over
{
//if (actualScore >= 5000)
// winText.text = "Good Job";
Debug.Log("Activated, Auth begins");
Social.ReportScore(50000, "CXXXXXXXXXXXXXXXXQ", (bool success) => {
});
PlayGamesPlatform.Activate();
Social.Show$$anonymous$$erboardUI();
}
}
So I don't see what I'm doing wrong now as I've done this before...
Your answer
Follow this Question
Related Questions
Google Play Services leaderboard not updating after high score is beaten? 1 Answer
Finding the max Y position value in a list of game objects and assigning it to a variable? 0 Answers
Running C# Function from JS file 0 Answers
i need help with my board manager coding ASAP 1 Answer
Hololens sharing example 1 Answer