Reputation: 11
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
Reputation: 922
Several suggestions:
onSoomlaStoreInitialized
event and start querying the inventory only after that.PlayerPrefs
yourself.Upvotes: 0
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