How to Add a FREE Online Leaderboard to Your Unity Game
In this article, we will integrate a free online leaderboard into a Unity project using ldrboard.com, the standard leaderboard tool for Unity game developers. The process involves setting up the leaderboard, customizing it, generating necessary code, and integrating it into a Unity game.
1. Login to Admin Dashboard:
- Go to admin.ldrboard.com and log in with your credentials.
- After logging in, select Create new game to set up the general information for your game.
- Choose a subdomain where the leaderboard will be hosted (e.g., newplatformergame.ldrboard.com).
2. Create the Leaderboard:
- Once the game is created, the initial leaderboard will be empty.
- To customize it, navigate to the ldrboard section in the admin panel
- In the "Schema" tab, add columns for the leaderboard such as level, kills, score, deaths, and time.
3. Adding and Organizing Columns:
- Add desired columns (e.g., level as text, kills as a number).
- Organize the columns by dragging them by the column header into the preferred order (e.g rank, user, level, kills, score, deaths, time, timestamp) and saving.
4. Selecting a Template:
- Choose from available templates to customize the leaderboard's appearance in the Design Tab.
- For example, select the circuitry template and configure settings such as sorting by level and best score.
5. Code Generation:
- Use the code generator on the website to generate the necessary code for the leaderboard.
- Configure your settings
Select Unity Engine from the gray dropdown
Enable Write
Player Unique Identifier
Device: Each player entry is tied to their device
Random: Each Player ID is generated randomly at runtime so players are not tied to their previous entry
Override: Each Player Entry is manually provided by you via code (useful when using another account system like Steam or Google Play)
Encryption
Strong
Uses RSA Encryption to encrypt ldrboard entries in game
Lightweight
Uses ARC4 Encryption to encrypt ldrboard entries in game
None
No encryption is done on submitted ldrboard entries (Recommended for testing only)
Use Session IDs
Tie entries together (useful for multiplayer games)
Use Game Versioning
Provide a game version with each request to allow for versioning your leaderboard when new game versions with different mechanics arrive
Use Timestamp
Provide a timestamp in milliseconds unix time manually instead of using the request timestamp
Override Platform
Set a platform for the ldrboard entry manually
Override Country
Set a country for the ldrboard entry manually instead of autodetecting the country code
- Generate
6. Integrate with Unity:
- Copy the generated code and paste it into a new script in Unity called Ldrboard.cs (That’s it!).
7. Script Modifications:
- In your game controller script, call the leaderboard write function with the relevant game state data (e.g., level, kills, score).
8. Compiling and Testing:
- Recompile the Unity project and ensure there are no errors.
- Run the game, play through it, and submit a score.
- Check the leaderboard page to see the new entry automatically populated.
This tutorial covered the essential steps to add a free online leaderboard to a Unity game. The process involves setting up and customizing the leaderboard, generating necessary code, and integrating it into your Unity project. The final result allows game scores to be submitted and displayed on the leaderboard seamlessly. Further customization and advanced settings will be explored in future tutorials. Check out the full video tutorial here and subscribe for future updates.
Want to add a leaderboard to your game? At ldrboard.com we help game developers quickly setup fully customizable leaderboards for their games for free. Follow us on Twitter (X) or join our Discord to get updates on all things leaderboard.