This tutorial will guide you through PubNub Prix, a racing game built using Unity's Karting Microgame and the PubNub Unity SDK to add a live leaderboard and in-app messaging that update in real-time.
You'll need the following before you begin:
Unity Personal (Free Version of Unity)
Download the PubNub Prix racing game from the GitHub Repository.
In a terminal, navigate to an empty folder of your choosing. Enter the following command to clone the repository.
Checkout the leaderboard-chat branch.
Follow the steps below to set up your environment.
To begin using PubNub in your Unity game, you'll need to import the Unity Package. Although this application already contains the dependencies you'll need, you might need to upgrade the PubNub Unity Package to a more recent version or if you wanted to add the package to another game.
Download the latest version of the PubNub Unity package (.unitypackage)
Open your application in Unity.
Once the dependencies have finished loading, import the package to the project by going to Assets > Import Package > Custom Package.
Finally, although the Namespace and Assembly Definitions are already added for this application, you can begin using the Unity PubNub SDK by adding the namespace to a file via
If you have imported the PubNub Unity Package to another application and added the namespace, you might receive CS0246 compiler errors if your Unity application contains existing Assembly Definitions. You will need to create an assembly definition to use the PubNubAPI in your application. If you are not receiving any errors, you can continue to the next step.
Navigate to the Assets > PubNub folder in the Project window.
Right-click the PubNub folder and create an Assembly Definition by selecting Create > Assembly Definition. Assign a name to the asset (such as PubNub) and leave the default settings.
Navigate to the folder that you wish to use the
PubNubAPI namespace. Click on the Assembly Definition file.
In the Inspector window, add the PubNub Assembly Definition you created earlier to the list of Assembly Definition References section by clicking on the
Scroll down in the Inspector window, and click Apply. The
PubNubAPI namespace should now be visible in your application.
You may receive more compiler errors when trying to use the
PubNubAPI namespace. These come from the PubNub > Editor folder, and contain test files. Delete the entire PubNub > Editor folder and allow the Unity editor to recompile changes.