Search Unity

Unity IAP not working.

Discussion in 'Unity IAP' started by infin1tygames, Jun 29, 2021.

  1. infin1tygames

    infin1tygames

    Joined:
    Jan 31, 2019
    Posts:
    2
    When i click on the IAP button in the editor i get these errors:
    upload_2021-6-29_9-21-17.png
    And when i publish the game and press the button on the phone nothing happens.

    Script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Purchasing;
    5.  
    6. public class SubManager : MonoBehaviour
    7. {
    8.     public GameObject panel;
    9.     public void OnPurchaseComplete(Product product)
    10.     {
    11.         if (product.definition.id == "subscription")
    12.             PlayerPrefs.SetInt("Sub", 1);
    13.  
    14.         panel.SetActive(false);
    15.         Debug.Log("Purchase complete");
    16.     }
    17.  
    18.     public void OnPurchaseFailure(Product product, PurchaseFailureReason reason)
    19.     {
    20.         Debug.Log("Purchase of product " + product.definition.id + " failed because " + reason);
    21.     }
    22. }
    23.  
    I have updated Unity IAP to the latest version but it didn't help.
    Also I imported the catalog to Google Play Developer Console.

    upload_2021-6-29_9-27-18.png
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    The error messages are indicating two things, 1) You are modifying a list while iterating through it and 2) you haven't got an active IAPButton or IAPListener in the scene when the purchase callback fires.

    So not directly connected with the code you posted.

    Edit: On second thoughts, it could be line 14, where you deactivate the panel, which is the cause of the 2nd error.
     
    Last edited: Jun 29, 2021
    infin1tygames likes this.
  3. infin1tygames

    infin1tygames

    Joined:
    Jan 31, 2019
    Posts:
    2
    Thank you! On the panel that I deactivated was that script, I replaced it to another object and this fixed all the errors
     
    Munchy2007 likes this.