This might not be the right place for this but I’m convinced it’s something I’m messing up in my code. I’m attempting to update a leaderboard in PlayFab. It connects and registers the player so that’s good. The method I’m using to update scores in the leaderboard doesn’t work however. Nothing shows up with my debug either.
This is the code I’m using to connect the player and its attached to an empty game object.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
public class PlayfabManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Login();
}
void Login()
{
var request = new LoginWithCustomIDRequest
{
CustomId = SystemInfo.deviceUniqueIdentifier,
CreateAccount = true
};
PlayFabClientAPI.LoginWithCustomID(request, OnSuccess, OnError);
}
void OnSuccess(LoginResult result)
{
Debug.Log("Successful login/account create!");
}
void OnError(PlayFabError error)
{
Debug.Log("Error while logging in/creating account!");
Debug.Log(error.GenerateErrorReport());
}
public void SendLeaderboard(int score)
{
var request = new UpdatePlayerStatisticsRequest
{
Statistics = new List<StatisticUpdate>
{
new StatisticUpdate
{
StatisticName = "HighScores",
Value = score
}
}
};
PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
}
void OnLeaderboardUpdate(UpdatePlayerStatisticsResult result)
{
Debug.Log("Succesful leaderboard sent");
}
}
This is my scoring script where I try to call the method… it’s attached to a separate empty game object.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class CollectableControl : MonoBehaviour
{
public static int scoreCount;
public static int highScoreCount;
public GameObject scoreCountDisplay;
public GameObject highScoreDisplay;
public PlayfabManager playfabManager;
void Start()
{
highScoreCount = PlayerPrefs.GetInt("highScoreCount", 0);
SceneManager.activeSceneChanged += OnSceneChanged;
}
void OnSceneChanged(Scene current, Scene next)
{
scoreCount = 0;
}
void Update()
{
scoreCountDisplay.GetComponent<TMPro.TextMeshProUGUI>().text = "" + scoreCount;
highScoreDisplay.GetComponent<TMPro.TextMeshProUGUI>().text = "" + highScoreCount;
if (scoreCount > highScoreCount)
{
highScoreCount = scoreCount;
PlayerPrefs.SetInt("highScoreCount", highScoreCount);
}
}
public void HighScores()
{
playfabManager.SendLeaderboard(highScoreCount);
}
}
Thanks in advance for any insights.