Hi everyone. I’m trying to implement soomla in app purchase and for linking my PurchaseNoAds function to my No ads Button I used the Onclick.addListener. Now when I click my button it works but it buy the item for 400 times before stopping, and it freeze my pc for a few seconds… Now my question is: where is the problem? In my Onclick.addlistener or in my in app purchase script? thanks for your time.
In app purchase script:
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
namespace Soomla.Store.Example
{ //Allows for access to Soomla API
public class NoAdsPayment : MonoBehaviour
{
public Button NoAdsButton;
//Load the Scene with the cube/ setup the soomla intergration
void Start ()
{
DontDestroyOnLoad(transform.gameObject); //Allows this gameObject to remain during level loads, solving restart crashes
StoreEvents.OnSoomlaStoreInitialized += onSoomlaStoreIntitialized; //Handle the initialization of store events (calls function below - unneeded in this case)
SoomlaStore.Initialize (new GameAssets()); //Intialize the store
}
//this is likely unnecessary, but may be required depending on how you plan on doing IAPS
public void onSoomlaStoreIntitialized(){
}
void Update()
{
if (Application.loadedLevelName == "Menù2") {
NoAdsButton = GameObject.Find ("NoADSButton").GetComponent<Button> ();
NoAdsButton.onClick.AddListener(() => PurchaseNOADS());
}
}
//GUI ELEMENTS
public void PurchaseNOADS() {
//Button To PURCHASE ITEM
if (StoreInventory.GetItemBalance("no_ads") == 0)
{
try {
Debug.Log("attempt to purchase");
StoreInventory.BuyItem ("no_ads");
Debug.Log (StoreInventory.GetItemBalance("no_ads")); // Print the current status of the IAP
if (StoreInventory.GetItemBalance("no_ads") == 1)
Debug.Log("EVVIVA");
}
catch (Exception e)
{ // if the purchase cannot be completed trigger an error message connectivity issue, IAP doesnt exist on ItunesConnect, etc...)
Debug.Log ("SOOMLA/UNITY" + e.Message);
}
}
else
{
Debug.Log("Already NOADS");
}
}