Easy and free online leaderboard in Unity! - PlayFab in Unity tutorial (#2)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey it's time to create a simple leaderboard and implement it into our game as always we'll use a playfab for that a free online service from microsoft that allows us to create a simple backend for our game make sure to check out other videos in the series where i set it up and explore different features of this service we will use as an example a simple game which i call the jumping john where the small innocent character called joan tries to reach the highest platform possible as you can see our game already counts platforms and i think it's a great idea to send this call to playfab leaderboard system let's start by creating a leaderboard in our online servers go to playfab dashboard and select game you'd like to work with in the left sidebar you'll find leaderboards option click it then click new leaderboard and rename it for our purposes i'll simply call it platform score reset frequency is a variable that determines how often the leaderboard should be wiped off automatically it can be used for leaderboards like daily best or monthly game seasons in our case i'll leave it to manually which means it won't be rested unless i select such option the last one rules how incoming scores will be saved you can choose to update player score with the last sent value no matter if it's higher or lower or you can specify to only update it if the value is better than the current one useful for high scores and lowest times to beat the level last but not least you can always sum incoming values which can be helpful to count how many times player has done any particle action as you might already guessed in our case we'll use the maximum option go ahead and press save here we have our newly created leaderboard but as you can see it's empty at the moment let's change it go to unity and open script called playfab manager here we need to create a new public method called send leaderboard let's type public void send leaderboard and as a parameter pass int score because a function should get a new score from the game manager and send it to leaderboard inside this method we'll call another playfab request and sidenote here in playfab api leaderboards are also called statistics so once again let's start with a request var request equals new update player statistics request open bracket statistics equals new list statistics update open bracket and finally new statistic update statistic update gets two values statistic name which in our case will be platform score and of course value which will be our score variable then type playfab client api dot update player statistics and other parameters pass requests on leaderboard update and on error then create a new method that will be called when system successfully sends leaderboard type void on leaderboard update update player statistics result result open bracket and type some useful debug information like successful leaderboard send that's it i'll quickly go to my game manager and call send leaderboard method that we have just created now i'll go back to unity press play and test the game a bit to get at least a few points now look at a console it shows error why that's because we need to allow our game to send scores to leaderboard go back to the playfab panel click gear icon title settings and finally api features here make sure to check a low client to post player statistics and save now once again go back to our game and test it look for the console and success to check out if everything looks fine in backhand go to the leaderboards panel playfab dashboard and click on delete the boat name as you can see here is our best score from the game go back to the code and create new function type public void get leaderboard this time won't pass any parameters and open bracket as always start with a var request equals new leaderboard request and add all info that we'd like to request start with a statistic name which will equal to platform score in our case start position which will be 0 and max results count which in our case will be 10. then call api playfab client api dot get leaderboard and pass request on leaderboard get and as always on error of course we miss on leaderboard get method so quickly create it void on leaderboard get get leaderboard result result and open brackets result has a list called leaderboard that has all info like position player name and score for each entry to write it nicely in the console type 4h var item in result.leaderboard open bracket and finally debug.log item dot position plus space plus item dot playfab id plus space plus item dot stat value that way for each leaderboard entry we should get a nice console output that writes down the position id and score for each player of course this is just a very simple output which in fact won't be visible to the user be sure to check out the future video all focused about unity ui system that will teach you how to design and display a simple leaderboard based on this data now save all your changes and go back to the unity the last step is to add a simple ui button that will send a request and output our leaderboard now it's time to test it out run the game and score bit after game over check the console if the score has been sent then click our newly created button and voila here is our leaderboard to test it even further i have compiled our game and played it on another computer unfortunately with current implementation i wasn't able to check the leaderboard so when i go back to our initial unity editor and press get leaderboard we can see that another score has been populated great remember that your game can have multiple leaderboards and it's up to you how you use and display them and that's it for this video be sure to subscribe if you like to be notified about any future playfab and unity ui videos also don't forget to like the video if you like to see more such tutorials see you in the next video
Info
Channel: Coco Code
Views: 69,476
Rating: undefined out of 5
Keywords: unity, cococode, bionicl code, bionicl, unity3d, Maciej maj, tutorial, guide, playfab, leaderboard, player statistics, gameplay, free service, no cost, easy to implement, easy
Id: e2RXDso6fWU
Channel Id: undefined
Length: 9min 31sec (571 seconds)
Published: Thu Sep 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.