Skip to main content
Space Rumble is a single-player mobile game built in Unity that demonstrates how to integrate several core PlayFab services into a real game loop. Players fly through a space arena destroying enemy satellites; their performance stats are posted to PlayFab leaderboards via event-triggered CloudScript.

Requirements

Unity 2018.3.1f1+

The project requires Unity 2018.3.1f1 or later.

Visual Studio 2017+

Visual Studio 2017 (Update 15.7) or later is required to build the project.

Android / iOS device

A physical or virtual device provides the best experience.

PlayFab title

The sample is pre-configured with Title ID FACD and works out of the box. Custom titles require additional configuration.

PlayFab configuration

If you use your own PlayFab title instead of the default FACD title, configure the following resources in the PlayFab Game Manager.

Leaderboards

Create the statistics below as Manual reset, Sum aggregation:
Statistic nameResetAggregation
games_playedManualSum
satellite_hitManualSum
satellites_destroyedManualSum
total_damageManualSum
total_round_timeManualSum

Title Data

KeyValue
MOTDA string displayed as the in-game Message of the Day

CloudScript

Add the following CloudScript to your title. The handlers read stat updates from PlayStream events and persist them to player statistics:
handlers.updateStatistic = function (args, context) {
  var event = context.playStreamEvent;

  if (event != null) {
    var request = {
      PlayFabId: currentPlayerId,
      Statistics: [{
        StatisticName: event.stat_name,
        Value: event.value
      }]
    };

    server.UpdatePlayerStatistics(request);
  }
};

handlers.updateStatistics = function (args, context) {
  var event = context.playStreamEvent;

  if (event != null) {
    var stats = event.stats;
    var statArray = [];

    for (var key in stats) {
      var value = stats[key];
      statArray.push({ StatisticName: key, Value: value });
    }

    var request = {
      PlayFabId: currentPlayerId,
      Statistics: statArray
    };

    server.UpdatePlayerStatistics(request);
  }
};

Automation rules

Create two PlayStream automation rules to link client events to the CloudScript handlers:
Rule nameEvent typeActionCloudScript function
update_statsticCustom Event — update_statsticExecute Cloud ScriptupdateStatistic
update_statsticsCustom Event — update_statsticsExecute Cloud ScriptupdateStatistics
The rule names intentionally match the event names emitted by the client, which contain the typos statstic / statstics. Use these exact strings when creating the rules.

Setup

1

Clone the repository

git clone https://github.com/Myst0gan1/PlayFab-Samples.git
2

Open the project in Unity

In Unity Hub, click Open and navigate to:
PlayFab-Samples/Samples/Unity/SpaceRumble
3

Configure PlayFab (optional)

The project defaults to Title ID FACD. To use your own title, update the Title ID via the PlayFab Editor Extensions or in PlayFabSharedSettings.asset, then complete the PlayFab configuration steps above.
4

Open the sample scene

Open the main scene from the Assets/Scenes/ folder.
5

Build and run

Build and deploy to an Android or iOS device, or press Play to test in the editor.

Using the sample

After passing the welcome screen you are prompted to sign in (existing account, new account, or guest). Once signed in:
  • Play — fly around the space arena and destroy enemy satellites.
  • Leaderboards — view rankings for all tracked statistics.
  • Options — set a custom display name or clear saved sign-in information.

Code structure

Scripts live in Assets/Scripts/, split into three groups:
Core gameplay logic: spaceship movement, collision detection, satellite spawning, and round timing.
Handles authentication, reading Title Data and User Title Data, posting PlayStream events (update_statstic, update_statstics), and fetching leaderboard data.
Manages the welcome screen, sign-in flow, main menu, leaderboard display, and options panel.

Key PlayFab features

User accounts

Email/password, guest, and remembered-session login using the PlayFab Auth APIs.

Title Data

Reads server-side key/value pairs (e.g., MOTD) to drive in-game content without a client update.

User Title Data

Stores per-player preferences and data dynamically created and updated from the client.

PlayStream events + CloudScript

Client fires custom events; automation rules route them to CloudScript handlers that update player statistics server-side.

Leaderboards

Displays ranked statistics for games played, hits, destroys, damage, and round time.

Build docs developers (and LLMs) love