To start out, checkout my GitHub and clone/download the repo. If you don't already have Unity installed, install it here. The repo contains an Assets folder which contains all of the Project Files. Open up Unity, and go to File -> Open Project and select the folder. It will take some time to load the project in Unity. When it completes, open up the Assets folder in your Project tab, and double-click on the LeaderBoard Unity Scene.
When you click on the LeaderBoard scene, you should see this:
To try out the demo, click the Play button at the top.
If you get the following error, follow the steps below:
Scene ‘LeaderBoard’ couldn’t be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.To fix this, go to File -> Build Settings. Click the Add Open Scenes button. Then go back to your Project tab, and double-click on the LeaderBoard, go back to your Build Settings, and click Add Open Scenes once again. Then in your Project Tab, double-click on the LeaderBoard scene again and run the project.
Now that your project is all set up, click the Run button. When you run the project, a PubNub Fire message is sent to the PubNub Function.As you can see in the screenshot below, when there are no scores stored in the KV Store, it will fill out every unfilled entry with "unset". Below I'm going to add some more entries to the KV store by typing in a username and score.
Lets add more entries. Lara, James, and Bob just got added to the highscore list below.
Now let's add Stephen to the list. As you can see, since his score is higher than Bob's but lower than James, he is placed in the 5th spot. All players that are connected to the game will see this score update in realtime. This logic is all done in the PubNub Function using the KV Store and array sorting. Click the try our demo button below to checkout how it works.
Open up two windows to see the high scores updating in real time




