What is Unity Multiplayer?
Unity Multiplayer is a shorthand for “Unity Multiplayer Networking,” which is Unity’s suite of tools for creating multiplayer games. Regarding online multiplayer, Unity took a giant leap forward in 2021. They extended Netcode for GameObjects at the time to be most useful for slow-paced, low-stakes, cooperative games and released it early. Additionally, DTLS encryption support was added to Unity Transport. In addition, the Unity team introduced new multiplayer services, including Unity Relay and Lobby, and the Network Profiler feature, at that time.
For multiplayer game support, the Unity development community had to use tools outside Unity until September 20, 2022. Netcode for GameObjects (NGO) 1.0 has been available for programmers ever since. The latter works with other recent Unity offerings, such as Game Server Hosting (Multiplay) and matchmaking tools. This update is part of Unity’s larger goal to make it easier for people to make online games by giving them different ways to do things. It’s important to note that Unity lets you combine their products with those of other companies to create a custom toolchain tailored to your needs.
Players can choose from a wide variety of multiplayer games. Here are some of them:
In player-versus-player (PvP) multiplayer games, two or more players compete against one another. Quite a few game styles are well-suited to this format. The multiplayer components of first-person and third-person shooters are a good example. PvP multiplayer modes can also be found in fighting and racing games (think Tekken or Street Fighter).
Games with cooperative multiplayer allow players to work together to take on the computer or solve puzzles.
Massive Multiplayer Online refers to online games with a large player count. This genre of games puts players in the same virtual world at the same time. Participants can communicate, engage in combat, solve puzzles or accomplish quests. World of Warcraft is a classic example of a massively multiplayer online game.
A MOBA, or multiplayer online battle arena, is a type of online multiplayer game where two opposing teams face off against one another. There is a fixed number of people on each team. The two groups will then face each other in a competition. League of Legends, Dota 2, and Valorant are all examples of successful multiplayer online battle arena games.
Create a Web Multiplayer Game
With the resources such as a Unity Game Development platform, creating a wide variety of Web3 multiplayer games is child’s play. The multiplayer mode in The Playground intelligently pairs off players and keeps everyone’s progress in sync. This means all players have access to one another’s character data, account information, etc. With Unity, we addressed these concerns.
We use ERC-20 tokens in The Playground to represent gold coins and ERC-721 tokens to represent NFT prizes. Because of this, players can consider the items they acquire in-game to be their own. These funds can be moved to another wallet without changing at all. This can be done either within the game itself or by the player outside of the game using their Web3 wallet. However, because this data is recorded on a distributed ledger (blockchain), all transactions and ownership information are publicly available.
It is now time to take a peek at the inner workings of our demo Unity MMO Web3 game.
The Playground – Demo
The Playground utilizes Web3 authentication, similar to other Web3 games and decentralized applications. After selecting the “Authenticate” option, customers can use their preferred mobile payment system to scan a QR code:
To begin playing alone, users need only click the “Play Game” button. We’ll be concentrating on multiplayer, though, for this piece. Additionally, all player instances will share a single desktop. But the same holds true for a computer network, whether on the same local area network or in different locations. For example, here’s a gamer who has successfully authenticated with his MetaMask wallet:
The gold coin count is displayed in the top left corner, and the number of NFT rewards is shown in the top right. The rules of the game can be found in the bottom left corner. But now, where the “Authenticate” button used to be, you’ll find the “Logout” button and then the account address of the fictitious user. If we press the “Play Game” button, the next room will appear as an example:
The “Start” or “Join” buttons must be clicked before our character can appear. Nonetheless, we must select “host” because this is the first participant. First, we’ll run a few different builds to simulate the multiplayer mode properly:
Local Four-Player Demonstration
Four separate players have been verified; they appear in the top image. Everyone is welcome to participate. Unfortunately, we can only show four at a time. If you look closely, you’ll notice that we used the same address for all but the player in the top left corner. For this reason, they will be able to see the effects of token transactions on their displays. Each player would need their own money.
Through the “View Setting” menu, each gamer can randomly generate a new user name and reset their data (to be treated as a new player):
And in each of those four instances, we initiated play by clicking the “Play Game” button. Then, we join the first build (P1) by clicking “Start (Host)” and using the other three forms (P2, P3, and P4) to “Join” it:
Consequently, all four players are now privy to one another’s identities, including screen names and cryptocurrency wallet IDs:
We can check the timing by switching around the players (see the video below, starting at 10:11). The physics is also correct; the heroes can’t walk into the lava pit but can cross the bridge. Right-player collisions are also present. Additionally, the “space” button can be used as a “hello” by any player:
Other than Web3 authentication, Unity Multiplayer supports all of these functions. Gold coins (ERC-20) and NFT rewards can be transferred to other players by simply clicking on them (ERC-721).
Token Transfers Inside The Playground
Thus, let’s use P1 in the top left corner to move tokens to another player. Remember that they all share the same address so that tickets will be distributed equally among them. The sender decides which tickets to send after clicking on another player. In addition, the addresses associated with a potential transaction are shown on the interface:
Following the selection of the target assets, the player must confirm the transaction by using their wallet (the connected wallet):
After verifying the transaction with the linked wallet, the “Waiting For Transaction” message displays.
After the on-chain transaction is confirmed, the recipient will receive the following message:
Shortly after the message is delivered, the recipient will also receive tokens, increasing their total (from 150 to 175):
Naturally, the same holds for award transfers (ERC-721 NFTs).
How to Build a Web3 Multiplayer Game Using Unity
Your curiosity to try out our demo game for yourself has been piqued, we assume, after watching the demonstration. Our sample Web3 multiplayer game’s source code is available on GitHub, so it should take a little time to whip up your copy. Even though we laid out the steps at the beginning of this article, let’s do a quick overview once again:
Please check out the GitHub, as mentioned earlier, page.
It’s available for download as a repository (*.zip or *.git).
You can access the repository by opening it in the Unity editor.
Following the instructions in the “README.md” file, install Unity.
Install the server by following the “Using Unity & PlayFab” guide.
For the fifth step, disregard the “.NET” instructions. The “Using Unity & PlayFab” tutorial and Visual Studio Code can be utilized when integrating the application settings and PlayFab features provided by Azure.
Looking to Create Your Own Web3 Multiplayer Game?
After reading the section above, the knowledge and tools to create your own copy of The Playground are at your disposal. Take a look at the video (at 5:11) below to better understand how to get things done. To reach the point where such a game can be released to the public, however, you’ll need to deploy your smart contracts. The latter handles token creation and trading for you. In addition, the “Lan” option is where you should concentrate while you test the multiplayer features:
Playing around in The Playground will give you the experience and knowledge you need to move on to developing your Web3 multiplayer games. Now is your chance to unleash the full potential of Unity’s online multiplayer. Adding a “web companion” dapp can also be extremely helpful. After all, using this type of dapp, you can make scoreboards, provide nifty dashboards, grant access to staff admins, and implement various other administrative purposes. Start watching the video below at 13:16 to get an idea of how our sample web companion dapp for The Playground works in practice.
Here is the video guide we’ve been talking about throughout this entire “create a Web3 multiplayer game” operation:
How to Build a Web3 Multiplayer Game Using Unity Multiplayer – Summary
With the latest update to Unity’s features, you can skip using external tools to handle the multiplayer component of your game. Since then, Unity has grown into an even more potent instrument. You also learned how to use Unity to create a Web3 multiplayer game, which is a step up from what you learned here. For this, you’ll require the best provider of Web3 APIs. In contrast, the latter gives you access to fundamental Web3 capabilities. Simple lines of code can be copied and pasted documentation into your existing codebase. You got to experience firsthand an example of a Web3 multiplayer game we built.
A Web3 multiplayer game can now be created with the knowledge of the necessary resources and procedures. If you’re starting Web3 development, we recommend first looking into some easy-to-follow challenges. you can also learn a lot about other aspects of blockchain technology development by perusing these publications. Our most recent posts cover a wide range of topics, including but not limited to developing Ethereum decentralized applications (dapps), using MetaMask to log in to Web3 Firebase, creating a decentralized website on Ethereum, developing Solana smart contracts, and more.
In addition to using the aforementioned no-cost tools, consider investing in blockchain certification.
Crypto Current will be guiding all of you who are new to the cryptocurrency world to becoming a cryptocurrency and blockchain expert. Crypto Current was founded to give access to information to everyone on current events occurring in cryptocurrency and blockchain in a digestible way. Since its creation, we have created content that impacted thousands of people through its podcast, blog, and social media.