There are many ways to monetize your mobile game. In-app purchase is the most popular one. But in Unity, it didn't have a straight forward steps to setup and manage IAP. You need a bit coding to intergrade into your project and hard code the product data into your code.
In this tutorial, you are going to learn the simplify workflow of using in-app-purchasing in Unity with IAP Manager. IAP Manager will take care all the logic of purchasing, buy button, price display and restore product. Minimal coding is needed.
Workflow of using IAP Manager
1. Setup Products in App Store
Follows the links below to setup products for in-app-purchase in each store. You will define the unique product id and product type for each product. For product such as coin or gold, you may setup as a consumable product. If your product is allowing to remove the advertisement, you may setup as a non-consumable product.
Tips: You can use same product id across store to simplify the workflow
2. Import IAPManager and Unity IAP
Setup Unity Purchasing Services
You can follow the tutorial below to setup Unity Purchasing Services (The scripting part is not requested).
Download and import IAP Manager
Goto Window>Asset Store and search IAP Manager and import to your project. Or, Download IAP Manager in Asset Store directly.
3. Setup IAPManager in your scene
1. Drag and Drop the IAP Manager prefab into the scene. You can find the prefab from “Digicrafts/IAPManager/Prefab/IAPManager.prefab”.
2. Select the IAPManager object and open inspector. Set the number of products you have. Select the product type and fill the product ids.
3. Setup Buy Button in your scene
1. Create a UI Button in your scene by right click on the hierarchy window.
2. Connect the button to corresponding product.
3. (Optional) You can create a label to display the product title or price automatically.
4. (Optional) If your game have a non-consumable product. You can create a restore button and connect to the IAP Manager.
5. Play now. You should see the button fill with test data.
4. Connect the script object to IAPManager
1. Create an empty game object in your scene and add a new script with the following content. You can add the code to delivery your product here such as remove ads or reward coins.
2. Drag the game object with the script to the Event Target of IAPManager.
3. Now, you can test your app for In-App Purchase.
Enabled Local Receipt Validation
IAP Manager also allows you to add client side receipt validation. Open player settings (Edit>Project Settings>Player). Add “RECEIPT_VALIDATION” in the Scripting Define Symbols.
Then, you need to add the obfuscating encryption keys. Unity IAP provides a tool that can help you obfuscate your encryption keys within your Application. This confuses or jumbles the keys so that it is much harder for a user to acces them. In the Unity menu bar, go to Window > Unity IAP > IAP Receipt Validation Obfuscator. Place the Google Play Store Public Key here and press Obfuscate secrets.
Prepare for Amazon App Store
Amazon kindle use Android as platform. You need to package the apps with Android Apps.
Before build to Amazon, please select Window>Unity IAP>Android>Target Amazon. Then, start build your Android apk.