I'm new to Playfab and using Unity. I'm having trouble getting my score to get sent to my Leaderboard. The player connects and logs in fine but I get no information to the score. These are my two scripts.
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");
}
}
and...
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);
}
}