The Leaderboards Unity Building Block demonstrates score-keeping in a game and generates a leaderboard to display player scores. Each score is stored as player data on the cloud.
The Leaderboards Building Block uses the following Unity Gaming Services (UGS):
| Unity Gaming Service | Description |
|---|---|
| Leaderboards | Stores, retrieves, and displays your player scores. |
| Authentication | Provides a unique identity to the player. In the Leaderboards test scene, this service allows users to sign in anonymously. |
| Access Control | Determines the authentication requirements for interacting with other services. This Building Block uses Access Control to stop players from writing data to Leaderboards. To write to Cloud Save, use the Trusted client which uses Cloud Code Modules to authenticate the calls as a trusted source. For more information, refer to Change the client in the Leaderboards test scene. |
| Cloud Save | Stores each score as Player Data and Game Data. |
| Cloud Code | The Cloud Code service allows you to create code that runs in the cloud. This code can authenticate a player as a trusted server or a client depending on your needs and interact with other services. This Building Block uses Cloud Code to demonstrate server-authoritative actions to store and retrieve player scores. The Leaderboards Building Block uses the following Cloud Code C# modules: Assets/CloudCode/BlocksAdminModule.ccmrAssets/CloudCode/BlocksGameModule.ccmr
|
To set up a project for the Achievements Building Block, follow the instructions in the LiveOps Building Block prerequisites.
To use all features of the Leaderboards test scene, perform the following actions.
The test sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary uses the BlocksGameModule.ccmr Cloud Code module to update the global score. To use this Cloud Code module, deploy it in the scene:
The test scene uses a configuration file to add data to a leaderboard. The Leaderboards test scene includes the simple_leaderboards.lb configuration file. To display a populated leaderboard in the test scene, deploy this file:
simple_leaderboard.lb checkbox.
If you want to use a Trusted game client, also select LeaderboardsAccessControl.ac.To learn about Leaderboard configuration on the Unity Dashboard, refer to Create a leaderboard.
The Leaderboards Building Block test scene contains a guessing game that generates a score based on how close your guess is to a randomly generated number. The result of this game appears on a leaderboard. You can also generate other random player scores.
To open the Leaderboards test scene:
To use each element in the Leaderboards test scene:
To reset the Leaderboard scores:
leaderboard.lb and select Reset Leaderboard.
To use the Leaderboards Building Block in a new scene, add the following prefabsAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary from the Leaderboards Building Block to your scene:
LeaderboardPrefab.prefab adds an empty leaderboard, and displays scores that the client fetches from the Leaderboard service. Find it in the Project window: Assets > Blocks > Leaderboards > Prefabs
UnityServices.prefab in Assets > Blocks > Common > Prefabs to initiate Unity Gaming Services.To use the Leaderboard prefab:
You can change the content, description, and appearance of the Achievements Building Block, and the type of client the Leaderboard uses.
You can change the rules for the leaderboard in the simple_leaderboard.lb configuration file:
simple_leaderboard.lb file to display its properties in the Inspector window.Toggle each Advanced Setting to apply the following leaderboards concepts:
To synchronize changes to the configuration file on the cloud, deploy it.
A leaderboard client submits scores to the Leaderboard service. The Leaderboards Building Block includes the following leaderboard clients:
LocalNumberGameClient): The local client submits scores directly to the Leaderboards service and doesn’t validate each score. You can use an Access Control policy to stop players from cheating by submitting their own scores.TrustedNumberGameClient): The remote client calls the Cloud Code C# module to submit the score.To change the client the leaderboard uses:
The LeaderboardsAccessControl.ac file is an access control asset that prevents users from cheating by adding their own scores to a leaderboard. It uses player authentication to deny unauthorized access to the leaderboard service.
For more information, refer to Access Control for Unity Gaming Services (UGS).
To use an access control asset, set the leaderboard client to Trusted. For more information about access control, refer to How to use Access Control.
If the score doesn’t appear on the client and a warning message appears, this indicates that the local client isn’t working correctly. This is because the LeaderboardsAccessControl.ac file denies write access to players.
To fix this issue:
LeaderboardsAccessControl.ac file.