Description
A daily prize wheel gives players one spin per day in exchange for a Spin Ticket. Each spin awards a random prize drawn from a weighted drop table. Because Spin Tickets are backed by PlayFab’s regenerating Virtual Currency, the rate of ticket accrual is fully server-controlled—players earn one ticket every 24 hours and can bank up to five at a time. From the player’s perspective, they tap a button, watch the wheel spin, and receive a prize. The server handles the ticket deduction and prize selection atomically, so the outcome cannot be manipulated client-side.How it works
Authenticate
The client calls one of the PlayFab authentication methods (for example,
LoginWithCustomID) to obtain a valid session ticket. A session ticket is required for all subsequent Client API calls.Trigger a spin
The client presents a spin button. When pressed, it calls
PurchaseItem with ItemId: "PrizeWheel1", VirtualCurrency: "ST", and Price: 1.PlayFab processes the purchase
PlayFab atomically:
- Deducts one Spin Ticket (ST) from the player’s Virtual Currency balance.
- Awards the
PrizeWheel1bundle to the player’s inventory. - Evaluates the bundle’s drop table (
PrizeWheel1) and grants the resulting item. - Returns the updated inventory and prize details to the client.
If the player has zero Spin Tickets,
PurchaseItem returns an error. The client should display the time until the next ticket regenerates using the VirtualCurrencyRechargeTimes field returned by GetUserInventory.PlayFab building blocks
- Accounts — player authentication and session management
- Virtual Currency — Spin Ticket (ST) with built-in recharge rate and cap
- Catalog — the
PrizeWheelcatalog containing prize items and the bundle - Drop Table — weighted random prize selection (
PrizeWheel1) - Player Inventory — item storage for awarded prizes
Setup
Create the Spin Ticket virtual currency
In Game Manager, go to Economy > Currencies and select New Currency. Enter the following values:
Select Save Currency.
| Property | Value | Detail |
|---|---|---|
| Code | ST | Abbreviation for the Spin Ticket currency |
| Name | Spin Ticket | Display name of the currency |
| Initial Deposit | 1 | Ensures every new player can spin immediately |
| Recharge Rate | 1 | Regenerates 1 ticket per day |
| Recharge Max | 5 | Players can bank up to 5 tickets at a time |
Create the PrizeWheel catalog
In Game Manager, go to Economy > Catalogs and create a new catalog named PrizeWheel.
Upload the drop table
Inside the PrizeWheel catalog, navigate to the Drop Tables tab and upload
DropTable.json. The drop table defines the weighted odds for each prize on the wheel.Upload the catalog items
Return to the top-level catalogs view. Click the arrow on the PrizeWheel catalog card, choose Upload JSON, and provide
Catalog.json. The catalog includes:Card1,Card2,Card3— the prize cardsSpinAgain— a bundle that awards one free Spin Ticket (ST)PrizeWheel1— the purchasable bundle (costs 1 ST) that references the drop table
The CloudScript
The prize wheel mechanic requires no CloudScript—the entire flow is driven by the Client API’sPurchaseItem call. PlayFab handles the Virtual Currency deduction and bundle/drop-table evaluation server-side automatically.
The JavaScript example calls PurchaseItem directly:
Running the example
- Unity 3D
- JavaScript
Install the PlayFab Unity SDK
Download and import the latest PlayFab Unity SDK into a new or existing Unity project.
Import the recipe package
Download and import PrizeWheelRecipe.unitypackage.
Set your title ID
Select the
PrizeWheel GameObject and set the Title ID field in the Inspector to your PlayFab title ID.