But there’s still more to do! If you followed Part 1 of our guide, you’ll have a fully functional Wordle game – but it’s offline, and it has no way for players to share and compare their scores. The original Wordle is great but we think it could be made better with a few features and mechanics that LootLocker can provide.
In this second part of our guide, we’ll use LootLocker to add the all-important social features. For example:
Check out our website to see how we can help you make your most creative game ideas a reality. LootLocker works straight out of the box, and makes the less exciting aspects of game development quick and easy.
Now let’s get started.
We’ll start off by creating a LootLocker account and setting a few things up - don’t worry this is all totally free.
(If you’ve already got a LootLocker account, you can skip straight to part 2.2.)
Now it’s time to install LootLocker into our Unity project.
We’re going to install the LootLocker SDK into Unity.
To do this, we need to install Git first. This will allow us to add the SDK into our project quickly and easily. (If you already have Git installed, you can skip straight to part 3.)
Now with Git installed, we can add LootLocker to our Wordle project.
Quick note: You might need to restart Unity before it recognizes you’ve installed Git.
Unity will now have a quick think and then start downloading the LootLocker SDK.
And that’s it. We now have the SDK installed. Simple, huh?
Now we’ve installed the SDK, we’ll turn on the feature we’ll use for this part of the guide.
Now we have our LootLocker settings just how we want them.
We need to tell the LootLocker SDK in Unity what game it should be referencing.
First we copy the identifier for our game – our API key.
Head back to the LootLocker dashboard (https://my.lootlocker.io) and click on the cogwheel again:
Click Game Settings:
Click the API tab and copy the API key. (Select the text and hit Ctrl+C):
Inside Unity, go to Edit -< Project Settings and click LootLocker SDK:
Now paste your copied API key into the Api Key field:
Now Unity and LootLocker can communicate.
Now it's time to write the code that will communicate with the LootLocker server.
Quick test: Head back into Unity and press play. The console should say: “Successfully started LootLocker session”. This means everything’s working and we’re connected to the server.
As our game is now, the player gets a new word every time they start the game. We don’t want that though. We want all players to get the same word.
Here’s how we achieve this:
This is how we get the current date online and format it:
This function will get us the current time. We then format it so we only have the information about the current date left.
This means that whenever a player logs in, they’ll get the same number as any other player who logs in at the same time.
We want to get the same output with the same input. This is why we do our own random function – rather than using a built-in one.
We can do this using an implementation of Xorshift. To explain it simply: it moves bytes around so you get a new number that looks nothing like the one you put in.
We won’t go into detail about how an Xorshift works. But if you want to read more about it, the Xorshift Wikipedia page will give you a deeper explanation.
Create a new C# script and name it Rand.cs:
Change the selection of the random word to use this new implementation. Add a reference to the PlayerManager:
In the function GetRandomWord(), change this:
Now go back into Unity and drag the reference for our PlayerManager to the GameController:
Quick test: Press play and you should get a random word in the console. And then when you play again, you should get the same word for the rest of the day.
At the moment, our version of Wordle is storing its words inside the game. This comes with a few disadvantages. For example: we can’t add or remove words without making a new game version.
So instead, we’ll store our words on LootLocker. This gives us much more flexibility.
With our words stored on LootLocker, we could even add multiple languages to our Wordle game without even needing to update the game itself. (This is a big task though, so let us know if it’s something you want our help with.)
We’ll create an asset on LootLocker to store all our words.
We start by configuring a Context.
Retrieving things from LootLocker isn’t instant. We need to do everything in the right order.
We’ll create an IEnumerator called SetupRoutine() to handle this for us. It’ll do everything in the right order and wait until the current step’s done before it goes onto the next one.
We’ll do this in GameController, but first let’s set everything up in PlayerManager.
Now we’ll change how we load things to get it all in the right order.
And that’s this part done.
Quick test: Press play in Unity. The console should now spit out a lot of information, before finally saying ‘Setup Done!’.
You can now remove the two files from the resource folder. We’re fetching them from the server now instead.
Games are more fun with a competitive edge, right?
So let’s give players the option to compete with each other on a leaderboard.
We’ll need to track the score a bit differently now. We’ll give the player a score of one to seven, based on how many guesses they needed to get the right answer.
Quick disclaimer: ‘Enable Game API Writes’ lets the game write directly to the scoreboard. This can be vulnerable to players submitting fake scores – if they’re really that competitive that they’re willing to cheat on such a simple game.
We’ll submit the players' scores to the leaderboard (using player IDs) when they enter the correct word.
In GameController.cs, we can now call this function when the player guesses the correct word.
Quick test: Take a quick break to play a round of your game. (Or you can use the Unity console to cheat). Click the View Scores button on LootLocker:
We now have a score uploaded. It’s really that easy.
We have a score system now. But that’s little use if the player has no place to actually view it.
So let’s add one.
Let’s go for the classic style of displaying leaderboard scores – players' names and leaderboard position on the left, and their score to the right.
In PlayerManager, add references to our newly created text components:
Add using UnityEngine.UI to the top of the script:
This next function will fetch the leaderboard and put the player names to the player names list, and the scores to player scores list. Add it to PlayerManager.cs:
We’ll update our leaderboard in Setup() in GameController.cs:
In Unity, drag the references to our two text components to our PlayerManager:
Quick test: Press play in Unity. The scores on LootLocker should now show up in the game as well.
We need buttons to open and close the leaderboard.
We now have our leaderboards set up.
But players can be sneaky. Once they’ve solved the puzzle once, they know what the answer is. So, if it really matters that much to them, they could play again and submit a perfect score to the leaderboard. Let’s stop them from doing that.
This is similar to what we do when we submit the score. A function takes the player score, and if the metadata matches, we give the player a popup saying to come back tomorrow instead.
Quick test: Play in the editor and guess the correct word. You shouldn’t be able to guess again until a new day arrives. (Although you can cheat by using your own seed. It’s your game after all.)
We want players to be able to enter their own names.
This is quick and easy to set up.
We’ll store our player’s name and let them change it whenever they enter something different. A popup will appear when they’ve changed their name. If they’ve changed it, their current name will show. Otherwise it’ll just say ‘Enter name…’
Set up these variables in PlayerManager.cs
public Text inputFieldPlaceHolderText;
public Text inputFieldText;
public InputField playerNameInputField;
Insert this function to handle name changes:
Call this function from Setup() in GameController. We don’t need to wait for this to finish – just call this directly after we’ve started the session:
In PlayerManager.cs, add this function to let the player change their name:
In GameController.cs, add a function to call this IEnumerator – and another IEnumerator to handle the waiting:
Set up references on PlayerManager:
On the Input field component, add a function call to ChangePlayerName() on On End Edit():
Quick test: Press play and change your name. A popup should…well, popup…to let you know if it worked. Restart the game and it should then show the name you entered before.
In the original Wordle you’re locked to one device. This can be troublesome if you, for example, want to play on your phone as well as your laptop. Since we are using LootLocker and have the player logged in, we can make that possible.
There are multiple ways to solve this:
A drawback of using any of these types of login systems is that we add another step for the player before they can play the game. The original Wordle just lets you play instantly. We want to keep that functionality.
So instead, we can use a unique identifier for the player, that they can copy to continue playing on another device.
The top Input field will show the player’s current ID. The field below it will let the player paste a new UUID.
Now we’ve got our UI set up, we need to add some code so that it can actually do something.
This next function will take the text of the changePlayerInputText and set it as the new player ID. Then it’ll restart the game, so the new player will be logged in.
Quick test: Press play and click on the Change Player button. The text should change to say the playerID isn’t valid:
Unity doesn’t support copying and pasting for WebGL out of the box. But the clever people from the internet have solved this for us.
(You can skip this part if you’re not planning to release your game as a Web GL version.)
This plugin has a MIT license, so we need to include that license in our project.
The Cancel button needs to close the ChangePlayerPopup. And another button needs to open the popup.
The player now needs a way to open this window.
Quick test: Make a build or open your project on another computer. Copy the ID and paste it onto the other device. You should now be logged in with the same account.
Playing games with friends is usually more fun than playing them alone, right? (Depending on who your friends are.) So let’s give players the option to play with friends. This also makes the game far more sticky as people can more easily compete with their friend group.
We’ll store the players' friends as assets in LootLocker. We’ll give them an ID that they can copy and paste to add someone as their friend.
This is fairly easy to set up – we can do it all in Unity.
The player's ID will need to be visible, so they can copy it and send it to someone else. And that player needs to have a field where they can add a friend's ID.
The player will then have the option to view just their friends scores or the global leaderboard.
Add these variables to PlayerManager.cs:
We’ll now fetch and populate our friends list like this:
Create a new IEnumerator in PlayerManager and call it SetupFriends():
In StartSession() take the playersId and set it to the Text of playerPublicID:
If we tried to run this now, nothing would happen – because we can’t add friends yet.
We’ll need a coroutine to add a new friend with information from the addFriendInputID Input Field. Once the friend is added, we’ll fetch the scores again to update the leaderboard.
Now we need input fields where we can paste our friends’ IDs. We also need a text field to share our own ID.
So there it is – you now have a fully working Wordle prototype that you can expand and improve however you like. As always, we've uploaded the game to Itch.io for you to play yourself, and uploaded the source code to Github for you to download. You can find both links below.
From here you could add different languages, an achievement system, a chat system, the sky's the limit!
Hopefully this guide has shown you how quick and simple it is to use LootLocker. Get in touch if you want to chat about how LootLocker can level up your game with backend features.
If you found this guide useful, let us know! Here are some great ways to join our community.