유니티 플레이팹 가상화폐 돈 증가 감소 간단 구현 Unity Playfab

반응형

기본 설정

public enum MoneyType
{
    Gold,
    Crystal
}

    public int gold = 0;
    public int crystal = 0;

 

돈 증가

    public void UpdateAddCurrency(MoneyType moneyType, int number)
    {
        string currentType = "";

        switch (moneyType)
        {
            case MoneyType.Gold:
                currentType = "GO";

                gold += number;

                break;
            case MoneyType.Crystal:
                currentType = "CR";

                crystal += number;
                break;
        }

        var request = new AddUserVirtualCurrencyRequest
        {
            VirtualCurrency = currentType,
            Amount = number
        };

        PlayFabClientAPI.AddUserVirtualCurrency(request, OnAddCurrencySuccess, null);
    }
    
    private void OnAddCurrencySuccess(ModifyUserVirtualCurrencyResult result)
    {
        Debug.Log("돈 증가 완료");
    }

 

돈 감소

    public void UpdateSubtractCurrency(MoneyType moneyType, int number)
    {
        string currentType = "";

        switch (moneyType)
        {
            case MoneyType.Gold:
                currentType = "GO";

                gold += number;

                break;
            case MoneyType.Crystal:
                currentType = "CR";

                crystal += number;
                break;
        }


        var request = new SubtractUserVirtualCurrencyRequest
        {
            VirtualCurrency = currentType,
            Amount = number
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(request, OnSubtractCurrencySuccess, null);
    }
    
    private void OnSubtractCurrencySuccess(ModifyUserVirtualCurrencyResult result)
    {
        Debug.Log("돈 감소 완료");
    }
반응형