PubNub Prix: Unity Application Environment Setup

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.

Prerequisites

You'll need the following before you begin:

Download Source Application

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.

1

Checkout the leaderboard-chat branch.

1

Follow the steps below to set up your environment.

Import PubNub Package

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.

  1. Download the latest version of the PubNub Unity package (.unitypackage)

  2. Open your application in Unity.

  3. Once the dependencies have finished loading, import the package to the project by going to Assets > Import Package > Custom Package.

PubNub Namespace

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 using PubNubAPI;

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.

  1. Navigate to the Assets > PubNub folder in the Project window.

  2. 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.

  3. Navigate to the folder that you wish to use the PubNubAPI namespace. Click on the Assembly Definition file.

  4. In the Inspector window, add the PubNub Assembly Definition you created earlier to the list of Assembly Definition References section by clicking on the + icon.

  5. Scroll down in the Inspector window, and click Apply. The PubNubAPI namespace should now be visible in your application.

  6. 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.

BackStep 1 of 4Next