Here is the IAPManager script, through which the purchase of advertising is disabled! After the purchase, the button does not work, then everything worked.

Apparently, I messed up somewhere with checking whether an advertisement was bought off! I'm doing under android!

 // Deriving the Purchaser class from IStoreListener enables it to receive messages from Unity Purchasing. public class IAPManager : MonoBehaviour, IStoreListener { public static IAPManager Instance{set;get;} private static IStoreController m_StoreController; // The Unity Purchasing system. private static IExtensionProvider m_StoreExtensionProvider; // The store-specific Purchasing subsystems. // public static string kProductIDConsumable = "consumable"; // public static string kProductIDNonConsumable = "nonconsumable"; public static string PRODUCT_NO_ADS = "noads"; private void Awake() { Instance = this; } private void Start() { // If we haven't set up the Unity Purchasing reference if (m_StoreController == null) { // Begin to configure our connection to Purchasing InitializePurchasing(); } } public void InitializePurchasing() { // If we have already connected to Purchasing ... if (IsInitialized()) { // ... we are done here. return; } // Create a builder, first passing in a suite of Unity provided stores. var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); builder.AddProduct(PRODUCT_NO_ADS, ProductType.NonConsumable); UnityPurchasing.Initialize(this, builder); } private bool IsInitialized() { // Only say we are initialized if both the Purchasing references are set. return m_StoreController != null && m_StoreExtensionProvider != null; } public void BuyNoAds() { BuyProductID(PRODUCT_NO_ADS); } private void BuyProductID(string productId) { // If Purchasing has been initialized ... if (IsInitialized()) { // ... look up the Product reference with the general product identifier and the Purchasing // system's products collection. Product product = m_StoreController.products.WithID(productId); // If the look up found a product for this device's store and that product is ready to be sold ... if (product != null && product.availableToPurchase) { Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id)); // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed // asynchronously. m_StoreController.InitiatePurchase(product); } // Otherwise ... else { // ... report the product look-up failure situation Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase"); } } // Otherwise ... else { // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or // retrying initiailization. Debug.Log("BuyProductID FAIL. Not initialized."); } } public void OnInitialized(IStoreController controller, IExtensionProvider extensions) { // Purchasing has succeeded initializing. Collect our Purchasing references. Debug.Log("OnInitialized: PASS"); // Overall Purchasing system, configured with products for this application. m_StoreController = controller; // Store specific subsystem, for accessing device-specific store features. m_StoreExtensionProvider = extensions; } public void OnInitializeFailed(InitializationFailureReason error) { // Purchasing set-up has not succeeded. Check error for reason. Consider sharing this reason with the user. Debug.Log("OnInitializeFailed InitializationFailureReason:" + error); } public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) { // A consumable product has been purchased by this user. if (String.Equals(args.purchasedProduct.definition.id, PRODUCT_NO_ADS, StringComparison.Ordinal)) { Debug.Log("No Ads"); } else { Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id)); } return PurchaseProcessingResult.Complete; } public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason) { // A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing // this reason with the user to guide their troubleshooting actions. Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason)); } } 

Here is the advertising indicator itself! He put both noads and PRODUCT_NO_ADS and even NoAds, but advertising still shows! And not after 5 losses, as I have, but when she thinks about it!

 void Start () { ///Реклама if (PlayerPrefs.GetString ("PRODUCT_NO_ADS") != "yes"){ //Должен проверять приобретено ли отключение рекламы! if (Advertisement.isSupported) Advertisement.Initialize ("4794523", false); else Debug.Log ("Platform is not supported"); } } 

It works when you lose!

 if (PlayerPrefs.GetString ("PRODUCT_NO_ADS") != "yes"){ //Должен проверять приобретено ли отключение рекламы! // advCount++; if (Advertisement.IsReady () && advCount % 5 == 0) Advertisement.Show (); } 
  • Is PlayerPrefs PRODUCT_NO_ADS exactly changed to yes? - Valera Kvip
  • ProcessPurchase - somewhere here with a successful purchase you need to make an entry PlayerPrefs.SetString (PRODUCT_NO_ADS, "yes") - Valera Kvip
  • If it's not difficult for you, can you tell me how to do this? - JonAlan

2 answers 2

Instead:

 // A consumable product has been purchased by this user. if (String.Equals(args.purchasedProduct.definition.id, PRODUCT_NO_ADS, StringComparison.Ordinal)) { Debug.Log("No Ads"); } 

Write:

 // A consumable product has been purchased by this user. if (String.Equals(args.purchasedProduct.definition.id, PRODUCT_NO_ADS, StringComparison.Ordinal)) { Debug.Log("No Ads"); PlayerPrefs.SetString(PRODUCT_NO_ADS , "yes"); PlayerPrefs.Save(); } 

And instead of:

 if (PlayerPrefs.GetString ("PRODUCT_NO_ADS") != "yes"){ //Должен проверять приобретено ли отключение рекламы! // advCount++; if (Advertisement.IsReady () && advCount % 5 == 0) Advertisement.Show (); } 

Write:

 if (PlayerPrefs.GetString (PRODUCT_NO_ADS) != "yes"){ //Должен проверять приобретено ли отключение рекламы! // advCount++; if (Advertisement.IsReady () && advCount % 5 == 0) Advertisement.Show (); } 
  • Thank! Now I will try, accomplish your goal! - JonAlan
  • Caused a similar error, that the context is not designated! /Scripts/player.cs(82,30): error CS0103: The name `PRODUCT_NO_ADS 'doesn’t exist in the current context - JonAlan 2:19 pm
  • @JonAlan IAPManager.PRODUCT_NO_ADS . - Suvitruf
  • I didn’t understand where to point this out! - JonAlan 2:32 pm
  • Where to point it? IAPManager.PRODUCT_NO_ADS, tried to do private static int IAPManager.PRODUCT_NO_ADS; but gives an error! - JonAlan 2:42 pm

Re-read your code carefully, and the second answer.

What should be done on the right. Break the problem into 2. And solve them separately. Problem 1 - ignore but ads. Problem 2 - does not work once out of five. First solve the problem by removing or committing all the code for the second problem, and only when it is no longer, add code for problem 2.

On the first problem, yes, at your time of purchase only Debug.Log ("No Ads") was made; and nothing was written in PlayerPrefs. This needs to be fixed exactly, as written in the next answer. Subject to the IAPManager.PRODUCT_NO_ADS fix from comments. Without this, NO_ADS will not work exactly. And using Equals ("yes") instead of = doesn't hurt either. In my project, I used to buy

 PlayerPrefs.SetInt("NoAds", 1); PlayerPrefs.Save(); 

and when checking

 PlayerPrefs.GetInt("NoAds") != 1 

On the second problem: it’s not clear how many times it is called by the given piece of the ad call code. Maybe this piece is spammed somewhere. In the update, for example, posted. And then you will not notice the difference, advertising is called once out of five frames, or just every frame.

  • Good try, thanks! - JonAlan pm
  • Unfortunately did not help! Do you have a similar script only working? To study it, maybe I was wrong somewhere in the code? - JonAlan pm
  • @JonAlan, I corrected the answer. Unsubscribe as checked. - Aleksandr Akimov pm
  • Maybe this is important, I have a product identifier in google - noads - JonAlan 5:41 pm