Build A Native Web3 Game (iOS, Android, Windows, Mac)

Learn how to create games with web3 functionality such as connecting to user wallets and minting NFTs using thirdweb's unity SDK.

Build A Native Web3 Game (iOS, Android, Windows, Mac)

In this guide, we'll show you how to build a mobile game on any native platform, such as iOS or Android using Unity and thirdweb's Unity SDK; part of our GamingKit to incorporate web3 capabilities such as connecting to user's wallets and minting NFTs into the gameplay.

Let's get started!

Creating A Web3 Unity Game

From within Unity Hub, create a new project to get started.

In this guide, we're going to use the 2D Mobile Unity template, but you can choose whatever is most relevant for you. Click Create Project to kick off the process.

Create a new 2D or 3D mobile project from Unity Hub

Install the thirdweb Unity SDK

To power the web3 functionality of the game, we'll be using our Unity SDK.

Head to the GitHub Releases page and download .unitypackage file from the latest version that is available.

Download the .unitypackage file

Add the package to your Unity project by clicking Assets > Import Package > Custom Package:

Import the .unitypackage file downloaded from GitHub

Leave the default files selected, and click Import:

Leave the default options. Click "Import".

In your Project window now, you'll be able to see all of the resources that were imported:

You should now see the Thirdweb folder in the Assets directory.

Now you’re ready to use the SDK!

Add A Connect Wallet Button In Unity

The Unity SDK comes with a ready-to-use Prefab to allow user's to connect their wallet to your game; the Native Connect Wallet Button Prefab.

To support the usage of the ThirdwebSDK class by these prefabs, we first need to add the ThirdwebManager prefab to our scene, from the /Assets/Thirdweb/Examples/Prefabs directory.

Once you've added that, create a new Canvas in your scene, and drag the ConnectWalletNative prefab from the same directory into the Canvas.

Select the ConnectWalletNative prefab

Focus the camera onto the Canvas to view what the prefab looks like:

Focus the camera on the canvas

Now your scene should contain the following:

  • The ThirdwebManager prefab
  • A canvas, containing the ConnectWalletNative prefab.

If we preview our game now, players can connect their wallet with three different methods, as defined in the prefab! Go ahead and try them out for yourself!

Preview of the game

Mint NFTs In Unity

Now we have our players connected to the game, let's add some web3 functionality such as minting NFTs!

For the purpose of this guide, we'll use the ready-to-deploy NFT Drop smart contract. You can follow the guide below to learn how to deploy your own, if you don't already have one:

Deploy an ERC721A NFT Smart Contract
In this guide, we’ll show you how to deploy and set up an NFT drop with ERC721A standards using the dashboard! Then, we will create a simple website using Next.js where users can claim the NFTs from the NFT drop. Let’s get started. Deploy the NFT Drop Smart Contract

Using the ThirdwebSDK, we're going to use the connected wallet to mint an NFT from our smart contract, using the Claim function.

First, let's add another button to our canvas that a user can click to mint an NFT:

Create a new button in the canvas with the text "Mint NFT"

Create a new C# Script in your project and use the following code to connect to your smart contract and claim an NFT to the connected wallet:

using UnityEngine;
using Thirdweb;

public class MintNFT : MonoBehaviour
    public async void Claim()
        Contract contract = ThirdwebManager.Instance.SDK.GetContract("0x-my-contract-address");
        await contract.ERC721.Claim(1);
Replace "0x-my-contract-address" with your NFT collection.

Attach this newly created script to the ThirdwebManager prefab in your scene, and then set the On Click of the "Mint NFT" button to call this Claim function:

Attach the Claim function to the Mint NFT button's on click handler

Now if we run the game we can successfully allow the player to connect their wallet and mint an NFT!

Connect your wallet and mint an NFT from the NFT drop!

To learn more about what functionality is available, check the Unity SDK documentation over on our portal:

thirdweb Unity SDK | thirdweb developer portal

Building Your Game

Now your game is ready to incorporate web3 functionality, let's see how we can build it for native platforms such as iOS, Android, and consoles!

To open the build settings window, click File > Build Settings.

Click Add Open Scenes, and select the platform you want to build your game for. In this guide, we'll use the Windows, Mac, Linux option to run it on a Mac machine. Install any required modules you need, and click Switch Platform.

Select the platform you want to build for

Once built, your game is ready to run on the device! On Mac, this gives us an application for us to run.

Once built, your game is ready to run!

Wrapping Up

In this guide, you've learned how to add web3 functionality into your Unity game, and build it for a native platform such as iOS or Android.

If you have any questions jump into the thirdweb Discord and join 32,000+ other builders! Please let us know if you have any feature requests or guide requests here.