Basic reward delivery pattern
This is a basic rewards system that utilizes the InGameCart and Deliverables helpers included with our SDK.
using Tebex.TebexUnity;
using Tebex.Headless;
using UnityEngine;
public class RewardManager : MonoBehaviour
{
[SerializeField] Deliverables deliverables;
[SerializeField] InGameCart cart;
// Assume you have these packages (fetched from Tebex.Packages or Tebex.PackageLookup)
[SerializeField] int goldPackageId = 1001;
[SerializeField] int mountPackageId = 1002;
void Start()
{
// Register what to do when each package is purchased.
deliverables.RegisterDeliverableAction(goldPackageId, OnGoldPurchased);
deliverables.RegisterDeliverableAction(mountPackageId, OnMountPurchased);
}
// After the player creates a basket and proceeds to checkout,
// hand the basket to Deliverables so it starts polling.
public void BeginWaitingForPayment()
{
Basket basket = cart.ActiveBasket;
if (basket != null)
{
deliverables.SetActiveBasket(basket);
}
}
void OnGoldPurchased(BasketPackage package)
{
int qty = package.in_basket.quantity;
Debug.Log($"Player bought {qty}x {package.name}. Awarding gold...");
// PlayerInventory.AddGold(qty * 1000);
}
void OnMountPurchased(BasketPackage package)
{
Debug.Log($"Player purchased: {package.name}. Unlocking mount...");
// PlayerMounts.Unlock("DragonMount");
}
}Last updated
Was this helpful?

