Gaming

A live leaderboard and lobby chat for a Unity game

Race a kart through the checkpoints to the finish line. Then submit your time to a top 10 leaderboard that updates for every player, and talk to other racers in the lobby chat. Built with Unity and the PubNub Unity SDK.

The PubNub Prix results screen: the top 10 leaderboard, your time with the Submit button, and the lobby chat
About this demo

A racing game with real-time features

PubNub Prix is Unity's Karting Microgame with real-time features added through the PubNub Unity SDK. It runs in your browser as a Unity WebGL build. Enter a name of up to six characters, drive with WASD or the arrow keys, and beat the clock to reach the results screen.

On the results screen, your time goes to a PubNub Function that keeps the top 10 in its KV Store and publishes the updated board to every player. The lobby chat sends and receives messages on a shared channel and loads recent ones from Message Persistence. A simple word filter replaces profanity in names and chat messages with asterisks. Each client gets an Access Manager token from a small token server before it talks to PubNub. The source code is open on GitHub, and the tutorial explains how the game is built.

Features

What you can do

  • Submit your time

    Finish the race and press Submit. The game publishes your name and time to the submit_score channel, once per race.

  • Rank against other players

    A PubNub Function runs after each submission. It places your time in the top 10 that it keeps in its KV Store, then publishes the new board.

  • Watch the board update live

    Everyone on the results screen subscribes to the leaderboard_scores channel. When anyone submits a time, the board changes for all of them at once.

  • See the board when you arrive

    When you reach the results screen, the game sends a Fire to the Function. Fire messages go only to Functions, and this one makes the Function publish the current board for you.

  • Chat in the lobby

    Type a message and every player on the results screen sees it right away. Messages with profanity have those words replaced with asterisks before they are sent.

  • Catch up on recent messages

    When the lobby opens, the game fetches the last 10 chat messages from Message Persistence, so you see what was said before you arrived.

Build it yourself

Make your own PubNub Prix

Follow the tutorial to see how the leaderboard and lobby chat are built, or clone the game and open it in Unity.

Tutorial

Add a live leaderboard and lobby chat to a Unity game

Set up your keyset and the leaderboard Function, then learn how the game submits times, updates the board, and runs the lobby chat.

GitHub

PubNubDevelopers/unity-karting-game

The complete Unity project. Check out the leaderboard-chat branch, add your publish and subscribe keys to GameConstants.cs, set up the leaderboard Function from the README, then build and run.

git clone https://github.com/PubNubDevelopers/unity-karting-game.git
View on GitHub
Keep building

Build interactive real-time experiences with PubNub

Bring chat, live updates, and real-time interactions into your application without building the infrastructure from scratch.