Advertisement
Frostyy22

.

Oct 14th, 2023
1,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using Unity.Services.Core;
  2. using Unity.Services.Economy;
  3. using Unity.Services.Economy.Model;
  4. using UnityEngine;
  5.  
  6. public class Economy : MonoBehaviour
  7. {
  8.     string slurpCoins = "SLURP_COINS";
  9.    
  10.     private async void Start()
  11.     {
  12.         await UnityServices.InitializeAsync();
  13.         await EconomyService.Instance.Configuration.SyncConfigurationAsync();
  14.  
  15.         GetBalance();
  16.     }
  17.  
  18.     private async void GetBalance()
  19.     {
  20.         CurrencyDefinition slurpCurrencyDefinition = EconomyService.Instance.Configuration.GetCurrency(slurpCoins);
  21.         PlayerBalance playersSlurpCoinsBalance = await slurpCurrencyDefinition.GetPlayerBalanceAsync();
  22.  
  23.         if (playersSlurpCoinsBalance != null)
  24.         {
  25.             Debug.Log($"Player's balance: {playersSlurpCoinsBalance.Balance}");
  26.         }
  27.         else
  28.         {
  29.             Debug.LogError("Failed to get player's balance.");
  30.         }      
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement