Is the IAP (In App Purchasing) tutorial applicable to Unity and C#?

I want to implement IAP for a free game that has ads by default. However, I want to create an in game button that removes the ads if the user chooses to pay. The tutorial you have on the site is for swift, but is it applicable to a game made with Unity and C#?

Hi @lunetech, I’d imagine it being slightly different in regards to setup in Unity and there being differences with the languages. I found this tutorial on the Unity website that might clear some things up for you, https://learn.unity.com/tutorial/unity-iap#5c7f8528edbc2a002053b46e.

Best,
Gina

Implementing Unity Ads

You must also initialize Unity Ads, whether or not you use the Codeless or manual IAP initialization method. The following code sample illustrates an initialization method to invoke:

using UnityEngine;
using UnityEngine.Monetization;

public class AdManager : MonoBehaviour {

  public bool testMode = true;
  private const string adPlacement = "video";
  private const string promoPlacement = "promo";

  #if UNITY_IOS
    private string gameId = "0000000"; // Your iOS game ID here
  #elif UNITY_ANDROID
    private string gameId = "9999999"; // Your Android game ID here
  #else
    private string gameId = "0123456"; // Prevents Editor Errors
  #endif

  private void Awake () {
    if (Monetization.isSupported && !Monetization.isInitialized) {
      Monetization.Initialize (gameId, testMode); 
    }
  }

  public void ShowVideoAd () { 
    ShowAdPlacementContent ad = Monetization.GetPlacementContent (adPlacement) as ShowAdPlacementContent; ad.Show (); 
  }

  public void ShowPromo () { 
    PromoAdPlacementContent promo = Monetization.GetPlacementContent (promoPlacement) as PromoAdPlacementContent; promo.Show (); 
  }
}

This topic was automatically closed after 166 days. New replies are no longer allowed.