PlaySuper LogoPlaySuper
Unity SDK

Core Usage

Initialize the SDK, create and login players, distribute coins, open the store, and check balances

Core Usage

This page covers the essential SDK methods you will call in every integration — from initialization to opening the store. Follow the steps in order.

1. Initialize the SDK

Add using PlaySuperUnity; at the top of your script, then call Initialize in Awake so the SDK is ready before any scene logic runs:

using PlaySuperUnity;

void Awake()
{
    // Production
    PlaySuperUnitySDK.Initialize("YOUR_API_KEY");

    // Development — points the SDK to the dev environment
    PlaySuperUnitySDK.Initialize("YOUR_API_KEY", isDev: true);
}
ParameterTypeDefaultDescription
apiKeystringYour game's API key from the PlaySuper console (required)
isDevboolfalseSet to true to use the development environment (dev.playsuper.club). Use false (or omit) for production.

Use isDev: true during development and testing. When you are ready to go live, remove the flag or set it to false so the SDK connects to the production environment.

If you regenerate your API key in the console, update the key in your code immediately — they must match.

Place the Initialize call in a top-level script attached to a GameObject in your first scene. This ensures the SDK persists across scene changes.

2. Create a player

Before you can distribute coins, register the player with PlaySuper. Call CreatePlayerWithUuid once per player, passing your game's internal user ID:

async void CreatePlayer()
{
    string playerUuid = "your-unique-player-id";

    var response = await PlaySuperUnitySDK.Instance.CreatePlayerWithUuid(playerUuid);

    if (response != null && response.data != null)
    {
        Debug.Log($"Player created with ID: {response.data.playerId}");
    }
    else
    {
        Debug.LogError("Failed to create player");
    }
}
ParameterTypeDescription
uuidstringYour game's unique identifier for this player (required)

You only need to create a player once. Store the UUID and reuse it for login on subsequent sessions.

3. Log the player in

After the player exists, authenticate them with LoginFederatedByStudio. The SDK stores the auth token automatically and uses it for all subsequent calls:

async void LoginPlayer()
{
    string playerUuid = "your-unique-player-id";

    var response = await PlaySuperUnitySDK.Instance.LoginFederatedByStudio(playerUuid);

    if (response != null && !string.IsNullOrEmpty(response.access_token))
    {
        Debug.Log("Player logged in successfully!");
    }
    else
    {
        Debug.LogError("Failed to login player");
    }
}
ParameterTypeDescription
uuidstringThe same UUID used in CreatePlayerWithUuid (required)

The auth token persists across sessions until it expires. On each launch, check IsLoggedIn() and re-login only if it returns false.

async void Start()
{
    if (!PlaySuperUnitySDK.IsLoggedIn())
    {
        await PlaySuperUnitySDK.Instance.LoginFederatedByStudio(playerUuid);
    }

    // Ready to distribute coins and open the store
}

4. Distribute coins

Once the player is logged in, award coins whenever they perform a rewarded action. Get the coinId from the Coins page in the console:

async void DistributeCoins()
{
    string coinId = "YOUR_COIN_ID";
    int amount = 100;

    await PlaySuperUnitySDK.Instance.DistributeCoins(coinId, amount);
    Debug.Log($"Distributed {amount} coins");
}
ParameterTypeDescription
coinIdstringThe coin ID from the PlaySuper console (required)
amountintNumber of coins to award (required)

If the player is offline or not yet logged in, the SDK queues the transaction locally and syncs it automatically once connectivity and authentication are restored.

5. Open the store

Let the player browse and redeem rewards by opening the PlaySuper store. The store uses the stored auth token automatically:

void OpenStore()
{
    PlaySuperUnitySDK.Instance.OpenStore();
}

You can also deep-link to a specific store page or add UTM tracking:

// Open directly to the rewards section
PlaySuperUnitySDK.Instance.OpenStore("https://store.playsuper.club/rewards");

// Open with UTM tracking
PlaySuperUnitySDK.Instance.OpenStore("https://store.playsuper.club/gcommerce", "main_menu_button");
ParameterTypeDescription
urlstringOptional — a specific store page to open
utmContentstringOptional — UTM content tag for analytics

6. Check login status

Before critical operations, verify the player is still authenticated:

bool isLoggedIn = PlaySuperUnitySDK.IsLoggedIn();

The token is stored locally and survives app restarts. If IsLoggedIn() returns false, call LoginFederatedByStudio again to refresh it.

7. Log out the player

When the player signs out of your game, call Logout to clear the auth token, profile, and all local session data:

void LogoutPlayer()
{
    PlaySuperUnitySDK.Instance.Logout();
    Debug.Log("Player logged out");
}

This clears:

  • Authentication token
  • Player profile data
  • User properties
  • Transaction sync state
  • Analytics event queue
  • All cached session data

After logout, the player must login again before they can distribute coins or open the store. Use IsLoggedIn() to verify authentication status.

8. Update player profile

Update the player's profile information after they're logged in. All fields are optional — only provide what you want to update:

async void UpdateProfile()
{
    var profile = await PlaySuperUnitySDK.Instance.UpdatePlayerProfile(
        firstName: "John",
        lastName: "Doe",
        email: "john.doe@example.com",
        phoneNumber: "+1234567890"
    );

    if (profile != null)
    {
        Debug.Log($"Profile updated: {profile.firstName} {profile.lastName}");
    }
    else
    {
        Debug.LogError("Failed to update profile");
    }
}

Available fields:

ParameterTypeDescription
firstNamestringPlayer's first name
lastNamestringPlayer's last name
genderstringGender: "MALE", "FEMALE", or "OTHER"
dateOfBirthstringDate in ISO 8601 format (e.g., "1990-01-01")
emailstringEmail address
phoneNumberstringPhone number in E.164 format (e.g., "+1234567890")

Example with demographics:

var profile = await PlaySuperUnitySDK.Instance.UpdatePlayerProfile(
    gender: "MALE",
    dateOfBirth: "1990-01-01"
);

Only provided fields will be updated. Omitted parameters leave the existing values unchanged.

Profile updates require the player to be logged in. Check IsLoggedIn() before calling this method.

9. Get the player's coin balance

Retrieve all coin balances for the current player:

PlaySuperUnitySDK.Instance.GetBalance((List<CoinBalance> balances) => {
    foreach (CoinBalance balance in balances)
    {
        Debug.Log($"Coin: {balance.name}, Amount: {balance.amount}");
    }
});
PropertyTypeDescription
idstringCoin ID
namestringCoin name
urlstringCoin image URL
amountintCurrent balance

Next, learn how to handle the store close event across platforms in Store Close Handling.