Guide to Using and Understanding Huawei InAppPurchase’s Demo Scene in Unity
Introduction
In this article, I aim to help you understand the in-app purchase better and easily add it to your game by explaining how you can use our second sample scene, which consists of two demo scenes, the Main Menu, and the Store scene, that we created for In-app purchase and how it works.
You can access demo scenes from the “Assets/Huawei/Demos/IAP/Second Demo-Menu_Store/” folder in version v2.3.4 of the plugin and above versions.
Steps to Use the Demo Scene:
- Complete the quick start steps.
- Activate the account kit and IAP from “kit settings”.
- Make sure that IAP and Account Kit are activated in the AppGallery Connect console. (If not, do so and refresh the agconnect-services.json file.)
- Add these products to the console with the same productIDs.
a. Product ID: coin100 — Type: consumable
b. Product ID: coin1000 — Type: consumable
c. Product ID: removeAds — Type: non-consumable
D. Product ID: premium — Type: subscription (1 week)
5. Add these products you added to the console to the window we prepared for IAP. Unity > Huawei > Kit Settings > IAP. Then click the “create constant classes” button.
6. Add the scenes to the scenes section in BuildSettings.
7. Disable the Initialize On Start.
Understanding Code Piece by Piece
SignIn:
Preliminary Procedures Required for In-app Purchase:
Using IAP — Store Scene:
Conclusion
With these two scenes, we tried to explain to you how you can use the managers we created for HMS, for example, for IAP and Account kit, in more than one scene. If you have any questions or suggestions, you can write to us by creating an issue on our GitHub repo or via our Discord channel.