EdwardMaya
EdwardMaya

Reputation: 11

Unity Soomla Score not updated when Purchase completed successfully

I implemented Soomla inn app purchase for android in unity it work fine but my score in not updated when purchase completed successfully what i do.I set the "android.test.purchased" for purchasing. Here is my Code

void Start () 
{
    PlayerPrefs.SetInt("Score" ,0)
}

void CheckIAP_PurchaseStatus()
{
    //What I do here ????? below check not working for me
    if (StoreInventory.IsVirtualGoodEquipped ("coinspack_a_item_id"))
    {
        PlayerPrefs.SetInt("Score" , PlayerPrefs.GetInt("Score") + 8000);    
    }
}

void OnGUI () 
{
    if (GUI.Button(new Rect(10, 10, 50, 50), "Buy"))
    {
        try
        {
            StoreInventory.BuyItem ("coinspack_a_item_id");                                 
        } 
        catch (Exception e) 
        {   
            Debug.Log ("SOOMLA/UNITY" + e.Message); 
        }
    }
}

Upvotes: 1

Views: 511

Answers (2)

Gur Dotan
Gur Dotan

Reputation: 922

Several suggestions:

  • Make sure you listen to the onSoomlaStoreInitialized event and start querying the inventory only after that.
  • Handle other SOOMLA events that are triggered to indicate a successful purchase. See here: http://know.soom.la/unity/store/store_events/
  • Consider using SOOMLA LevelUp - it's another open-source package that provides a rich model of worlds, levels, scores, missions, rewards etc. It also handles storage aspects for you so you don't need to call PlayerPrefs yourself.
  • Post this question to the SOOMLA forum: http://answers.soom.la/

Upvotes: 0

Andrei Bazanov
Andrei Bazanov

Reputation: 352

You are going about it the wrong way. You should really read the SOOMLA documentation. This is a quick YouTube tutorial that I have put together.

Basically you need to: 1 - Firstly, I would not manage the economy myself if I were you, I would rather let SOOMLA do it. If you have defined a currency pack, then on a successful purchase SOOMLA will automatically top-up your balance.

2 - Otherwise, if you want to do it yourself, then set-up the event handlers that SOOMLA offers and do it inside OnItemPurchased event which is fired after a successful market purchase.

3 - Make sure the Core and Store prefubs are on a Scene/Page that is loaded only once for the entire duration of the game.

4 - If you want to trap errors in the Store then don't do it with a try catch, instead set-up the OnUnexpectedErrorInTheStore event.

Please read the documentation here, and as a side note, not sure if you knew but SOOMLA have a dedicated support forum at answers.soom.la where you might get quicker answers.

Upvotes: 0

Related Questions