• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Stefano9528 · Oct 02, 2015 at 09:12 AM · soomla

Soomla In App purchase and onClick.addListener

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");
         }
         }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by meat5000 · Oct 02, 2015 at 09:12 AM

You need to reformat your code.

Is it always 400 times or does it get bigger as time goes on? Surely you need to add the listener only once and not every frame?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Stefano9528 · Oct 02, 2015 at 09:46 AM 0
Share

Thank you . I was Adding the listener every frame.

avatar image meat5000 ♦ Stefano9528 · Oct 02, 2015 at 11:22 AM 1
Share

No problem. Please click accept to accept the answer.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

In-App-Purchasing with Soomla problem 3 Answers

unity ios test in app purchase “verification failed” while login with sandbox tester user 0 Answers

CommandInvokationFailure: Failed to re-package resources 1 Answer

Soomla profile login error for android - ProviderNotFoundException 0 Answers

Soomla - Game Restart - Not handled 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges