question

stiglicmichal5 avatar image
stiglicmichal5 asked

How to show Leaderboards in UI (Unity) ?

Hi, i successfully post player score to leaderboard (via update player statistics) but now i want to show that score in UI how can i do that please?

Leaderboards and Statistics
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

It sounds like you're asking about the actual player presentation layer (displaying things to the user). If so, that's entirely up to you. PlayFab is a backend service that you can use for a wide range of server-side functionality, but we do not interfere in the presentation layer in any way. Your best bet would be to check the asset store for packages that can assist you with your user interface components.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

stiglicmichal5 avatar image stiglicmichal5 commented ·

Hi, thanks for reply! I can get and show player name like this:

public void GetAccountInfo()
        {
            
            GetAccountInfoRequest request = new GetAccountInfoRequest();
            PlayFabClientAPI.GetAccountInfo(request, OnGetAccountInfoSuccess, OnPlayFabCallbackError);
        }


        
        void OnGetAccountInfoSuccess(GetAccountInfoResult result)
        {    
            Debug.Log(result.AccountInfo.TitleInfo.DisplayName);
            DisplayNamee.text = result.AccountInfo.TitleInfo.DisplayName.ToString();
        }


      
       
        void OnPlayFabCallbackError(PlayFabError error)
        {
            Debug.LogWarning(error.ErrorMessage);
        }

And i want to make it also for player statistic ( statistic name is Kills ) how should i modify that code above to make it works for player statistics please?I really need help.Thank You!

0 Likes 0 ·
brendan avatar image brendan stiglicmichal5 commented ·

You already have the statistic name, since that's the ID you use to write the statistic to the player, so it sounds like you're asking how to query for the player's statistic values, so that you can display them, yes?

If you just want to get the player's own statistics, you can use:

https://api.playfab.com/documentation/client/method/GetPlayerStatistics

The returned data is a StatisticValue list - each containing the name of the statistic, its current value, and the version of the statistic.

If you want to show a whole leaderboard, you can use any of the GetLeaderboard type API calls (like https://api.playfab.com/documentation/Client/method/GetLeaderboard). Those return a list of PlayerLeaderboardEntry objects, which contain all the information you need about each user, including the profile information you're allowing to be returned via Settings->Client Profile Options), as well as the next reset time for the leaderboard, and the current version number for the statistic.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.