You can redeem Purchases to specifically the Player and even a Class that the Player owns!
Create In App Purchases on Apple
Navigate to the App Store Connect page, and find Monetization, Underneath you'll find In-App Purchases which is where you will create the Products and find the necessary information.
As you create a new In App Purchase, you need to pick a Type, a Reference Name and finally a Product ID. Create the Product and save the Product ID to create IAP with LootLocker.
Creating Purchases In Engine
To create Purchases in Unity, you must inherit from IDetailedStoreListener and import the required methods that follows.
usingUnity.Services.Core;usingUnity.Services.Core.Environments;usingUnityEngine;usingUnityEngine.Purchasing;usingUnityEngine.Purchasing.Extension;publicclassIAPManager:MonoBehaviour,IDetailedStoreListener{publicIStoreController controller;privateIExtensionProvider extensions;publicasyncvoidAwake() {try {var options =newInitializationOptions() .SetEnvironmentName("production");awaitUnityServices.InitializeAsync(options); }catch (Exception exception) {Debug.Log(exception); } //Specifically creates IAP for Google Play Store, using ifdefs to determine which platform is being run is preferable.
var builder =ConfigurationBuilder.Instance(StandardPurchasingModule.Instance(AppStore.AppleAppStore));builder.AddProduct("<replace_with_product_id>",ProductType.Consumable);StandardPurchasingModule.Instance().useFakeStoreAlways=true;UnityPurchasing.Initialize(this, builder); }publicvoidOnPurchaseClicked(string productId) {controller.InitiatePurchase(productId); }publicvoidPurchase() {var product =controller.products.WithID("<replace_with_product_id>");if (product is { availableToPurchase:true }) {controller.InitiatePurchase(product); } } /// <summary> /// Called when Unity IAP is ready to make purchases. /// </summary>publicvoidOnInitialized(IStoreController controller,IExtensionProvider extensions) {this.controller= controller;this.extensions= extensions; } /// <summary> /// Called when Unity IAP encounters an unrecoverable initialization error. /// /// Note that this will not be called if Internet is unavailable; Unity IAP /// will attempt initialization until it becomes available. /// </summary>publicvoidOnInitializeFailed(InitializationFailureReason error) { } /// <summary> /// Called when a purchase completes. /// /// May be called at any time after OnInitialized(). /// </summary>publicPurchaseProcessingResultProcessPurchase(PurchaseEventArgs e) {LootLockerIAPManager.RedeemPurchase(e.purchasedProduct);returnPurchaseProcessingResult.Complete; } /// <summary> /// Called when a purchase fails. /// </summary>publicvoidOnPurchaseFailed(Product i,PurchaseFailureReason p) { }publicvoidOnPurchaseFailed(Product product,PurchaseFailureDescription failureDescription) { }publicvoidOnInitializeFailed(InitializationFailureReason error,string message) {Debug.Log("Error: "+ message); }}
A guide is currently in the making as this requires a lot of set up! Once the guide is up, it will be linked here.
Redeem Purchase For Player
Product is from using UnityEngine.Purchasing;
Which is a Package called "In-App Purchasing", read more here.