Trending
Opinion: How will Project 2025 impact game developers?
The Heritage Foundation's manifesto for the possible next administration could do great harm to many, including large portions of the game development community.
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.
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
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
Setup Unity Purchasing Services
You can follow the tutorial below to setup Unity Purchasing Services (The scripting part is not requested).
https://docs.unity3d.com/Manual/UnityIAPSettingUp....
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.
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.
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.
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.
using UnityEngine; using System.Collections; using System.Collections.Generic; using Digicrafts.IAP; public class IAPDCExample : MonoBehaviour, IIAPDelegate { //--- IIAPDelegate // Event when IAP initialized public void OnIAPInitialized(Dictionary<string, IAPProduct> products){ // products contains a Dictionary whcih sotre product information foreach(KeyValuePair<string, IAPProduct> item in products){ Debug.Log("Id: " + key + " Product: " + p); } } // Event when IAP initialized Fail public void OnIAPInitializeFailed(string error) {} // Event when a purchase started public void OnIAPPurchaseStart(IAPProduct product) {} // Event when when a purchase finished and success public void OnIAPProcessPurchase(IAPProduct product, string transactionID, string receipt) { // You can delivery your products here such as add coins, remove ads // You can get the product information and receipt from here. } // Event when a purchase failed public void OnIAPPurchaseFailed(IAPProduct product, string failureReason){} // Event for deferred purcahse // On Apple platforms we need to handle deferred purchases caused by Apple's Ask to Buy feature. // On non-Apple platforms this will have no effect; OnDeferred will never be called. public void OnIAPProcessDeferred(IAPProduct product) {} // Event for restore purchase // Success set to true if restore success public void OnIAPTransactionsRestored(bool success) {} }
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.
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.
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.
SaveSave
SaveSave
SaveSave
SaveSave
Read more about:
BlogsYou May Also Like