{"__v":16,"_id":"548ae445b77bb70b00ac8cad","category":{"__v":14,"_id":"54890d71c178b40b00aa3086","project":"543b9b0065bf840e00b473d5","version":"543b9b0065bf840e00b473d8","pages":["548a63d41bd6c40b00f77728","548a6fbab77bb70b00ac8bf2","548adcb7b77bb70b00ac8c9d","548add501bd6c40b00f777d2","548ae445b77bb70b00ac8cad","548aef1bb77bb70b00ac8ccb","548af4b41bd6c40b00f777fc","548eb9d5e52d2b0b001b9a28","5508449ba42e812500b711f3","550a8eed42fff40d00ae60e3","550ce8fd6c0b4c0d00fd42fb","550ce9026c0b4c0d00fd42fd","550d840f11e8d00d00b80383","550e7e7f8387ac0d00ed9e1a"],"reference":false,"createdAt":"2014-12-11T03:20:17.529Z","from_sync":false,"order":5,"slug":"game-settings","title":"Game Settings"},"project":"543b9b0065bf840e00b473d5","user":"543b9aa865bf840e00b473d1","version":{"__v":11,"_id":"543b9b0065bf840e00b473d8","project":"543b9b0065bf840e00b473d5","createdAt":"2014-10-13T09:27:28.467Z","releaseDate":"2014-10-13T09:27:28.467Z","categories":["543b9b0065bf840e00b473d9","543b9ef065bf840e00b473e0","54890012f291f61400c02d36","54890902f291f61400c02d3e","54890c43f291f61400c02d44","54890d71c178b40b00aa3086","5508125c0c4d8c19008a5f83","55094050961f17170070abbd","550945111c38c50d006118ad","550a4c2e42fff40d00ae6049","55221c074801a40d00a77610"],"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"createdAt":"2014-12-12T12:49:09.793Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"basic_auth":false,"results":{"codes":[]},"settings":"","try":true,"auth":"never","params":[],"url":""},"order":2,"body":"The starter kit comes with a demo of 4 different purchasable items. You can add, remove, or customize every IAP.\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"IAP Included\",\n    \"h-1\": \"Description\",\n    \"0-0\": \"Dobbit Builder\",\n    \"1-0\": \"Soft Currency #1\",\n    \"2-0\": \"Soft Currency #2\",\n    \"3-0\": \"Hard Currency\",\n    \"1-1\": \"Default is Gold. The first of two currencies generated in the game.\",\n    \"2-1\": \"Default is Liquid Mana. The second of two currencies generated in the game.\",\n    \"0-1\": \"Default is 1. To create two buildings at once, at least 2 builders are required.\",\n    \"3-1\": \"Default is Gems. A currency that cannot be generated, only bought.\"\n  },\n  \"cols\": 2,\n  \"rows\": 4\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"IAP Menu\"\n}\n[/block]\nTest the In-App Purchase Menu by clicking the plus button (+) next to the gems or next to the construction workers in the menu buttons on the main screen.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://www.filepicker.io/api/file/8C0rO9wGQGu1ZrENHxu0\",\n        \"unity-iap-menu-touch-to-open.jpg\",\n        \"832\",\n        \"354\",\n        \"#837246\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://www.filepicker.io/api/file/ueO3LpAPQXi10g4MOKga\",\n        \"unity-mobile-app-iap-template-example.jpg\",\n        \"806\",\n        \"507\",\n        \"#386473\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"The demo IAP purchase routine is designed to use in-game currency, which you should sell in allotments. Otherwise you will want to edit the IAP script included to launch your IAP asset upon clicking the item's purchase button.\",\n  \"title\": \"Choose Your In-App Purchase Method\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"How to Setup In-App Purchases\"\n}\n[/block]\n\n[block:embed]\n{\n  \"html\": \"<iframe class=\\\"embedly-embed\\\" src=\\\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fk5pazOOnytQ%3Ffeature%3Doembed&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dk5pazOOnytQ%26feature%3Dyoutu.be&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fk5pazOOnytQ%2Fhqdefault.jpg&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=youtube\\\" width=\\\"854\\\" height=\\\"480\\\" scrolling=\\\"no\\\" frameborder=\\\"0\\\" allowfullscreen></iframe>\",\n  \"url\": \"https://www.youtube.com/watch?v=k5pazOOnytQ&feature=youtu.be\",\n  \"title\": \"How to Create IAP - Tutorial #5\",\n  \"favicon\": \"https://s.ytimg.com/yts/img/favicon-vflz7uhzw.ico\",\n  \"image\": \"https://i.ytimg.com/vi/k5pazOOnytQ/hqdefault.jpg\"\n}\n[/block]\nThe **HardPriceProc.cs** IAP script included with the Starter Kit (renamed to **MenuMain/PurchaseMenu.cs** for the Pro and Complete kits) manages the menu interactions. You can customize this script to create your own menu or interactions. The script processes the total amount based on the info in **HardPrice.xml** and calculates a **totalPrice** float variable. As you add or remove items, this **totalPrice** variable is added to or subtracted from like:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Add item price to totalPrice\\ntotalPrice += float.Parse (prices [currentSelection] [\\\"Price\\\"]);\\n\\n// Subtract item price from totalPrice\\ntotalPrice -= float.Parse (prices [currentSelection] [\\\"Price\\\"]);\",\n      \"language\": \"csharp\",\n      \"name\": \"Excerpt from HardPriceProc.cs \"\n    }\n  ]\n}\n[/block]\nWhen pressing the Buy button, the **totalPrice** variable needs to reach the solution you've picked for online purchases. [Add your own IAP routine with the totalPrice variable](http://answers.unity3d.com/questions/17180/iphone-in-app-purchase-tutorial.html) or get an asset such as [Simple IAP System](https://www.assetstore.unity3d.com/en/#!/search/iap).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public void Purchase()\\n\\t{\\n    // The totalPrice (float) variable at this point contains the\\n    // total cost of the player's order.\\n\\t\\t// Insert a reference to your purchase routine here using totalPrice.\\n  \\n    // ... Script source continues with increasing quanities purchased\\n    // ... and updating the HUD crystal, builder, and gold / mana values.\\n    // ... Not shown in this documentation excerpt.\\n\\t}\",\n      \"language\": \"csharp\",\n      \"name\": \"Excerpt from HardPriceProc.cs\"\n    }\n  ]\n}\n[/block]\nRemember to condition the resources increase in the main interface after the online purchase has been completed, and not just opening and canceling it.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"The purchase routine in **HardPriceProc.cs** or **PurchaseMenu.cs** does not connect directly to iOS or Android IAP systems. Before publishing your game, [add your own IAP routine](http://answers.unity3d.com/questions/17180/iphone-in-app-purchase-tutorial.html) or get an asset such as [Simple IAP System](https://www.assetstore.unity3d.com/en/#!/search/iap)\",\n  \"title\": \"In-App Purchases are Setup as a Demo\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"HardPrice.xml (Set in-app billing prices and quantities)\"\n}\n[/block]\nIn this file you can set the prices for each item to be purchased in the store and the amounts. \n\n- ** Builders: **Dobbit is what they're called (and the cost per additional building at one time) \n- **Hard-Currency:** Crystals is the name of the one hard-currency supported. \n- **Soft-Currency:** Gold is the first soft-currency and Mana is the second. You can rename the soft-currencies to anything you wish. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<Items> \\n  <Item>\\n    <Name>Dobbit</Name>   \\n    <Price>1</Price>\\n    <PerQuantity>1</PerQuantity>      \\n  </Item> \\n  <Item>\\n    <Name>Crystals</Name>   \\n    <Price>0.5</Price>\\n    <PerQuantity>10</PerQuantity>     \\n  </Item> \\n  <Item>\\n    <Name>Gold</Name>   \\n    <Price>0.7</Price>\\n    <PerQuantity>1000</PerQuantity>     \\n  </Item>   \\n  <Item>\\n    <Name>Mana</Name>   \\n    <Price>0.6</Price>\\n    <PerQuantity>500</PerQuantity>      \\n  </Item>       \\n</Items>\",\n      \"language\": \"xml\",\n      \"name\": \"HardPrice.XML\"\n    }\n  ]\n}\n[/block]\nIf you want to sell additional items: \n\n1. First add the item to **HardPrice.XML**\n2. Then in **HardPriceProc.cs**(renamed to **MenuMain/PurchaseMenu.cs** for the Pro and Complete kits) increase the itemsNo variable by 1\n3. Add an additional **OnBuy()** and **OnMinus()**[The methods are also named with a  numerical value at the end, eg: **OnBuy3()**, **OnMinus3()**, **currentSelection = 3**, so maintain numerical sequence when adding a new method]\n4. And add the item's allocation in the **Purchase()** function\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"HardPriceProc.cs References\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Reference\",\n    \"0-0\": \"dobbitNo\",\n    \"h-1\": \"Description\",\n    \"1-0\": \"maxCrystals\",\n    \"2-0\": \"crystals\",\n    \"1-1\": \"**(int)** If maxCrystals is 5, and I have 3 crystals and buy 5 more; maxCrystals is increased to 8 instead of 10 (sum of max + purchase)\",\n    \"2-1\": \"**(int)** The quantity of gems being purchased (hard currency)\",\n    \"3-0\": \"maxStorageGold\",\n    \"4-0\": \"gold\",\n    \"0-1\": \"**(int)** The quantity of builders being purchased\",\n    \"3-1\": \"**(int)** The maximum storage. Sum of Max + purchased.\",\n    \"4-1\": \"**(int)** The quantity of gold being purchased (soft currency #1)\",\n    \"5-1\": \"**(int)** The maximum storage. Sum of Max + purchased.\",\n    \"6-1\": \"**(int)** The quantity of liquid mana being purchased (soft currency #2)\",\n    \"5-0\": \"maxStorageMana\",\n    \"6-0\": \"mana\",\n    \"7-0\": \"totalPrice\",\n    \"7-1\": \"**(float)** The total purchase value. Send to your IAP routine.\"\n  },\n  \"cols\": 2,\n  \"rows\": 8\n}\n[/block]","excerpt":"","slug":"in-app-purchases","type":"basic","title":"In-App Purchases"}

In-App Purchases


The starter kit comes with a demo of 4 different purchasable items. You can add, remove, or customize every IAP. [block:parameters] { "data": { "h-0": "IAP Included", "h-1": "Description", "0-0": "Dobbit Builder", "1-0": "Soft Currency #1", "2-0": "Soft Currency #2", "3-0": "Hard Currency", "1-1": "Default is Gold. The first of two currencies generated in the game.", "2-1": "Default is Liquid Mana. The second of two currencies generated in the game.", "0-1": "Default is 1. To create two buildings at once, at least 2 builders are required.", "3-1": "Default is Gems. A currency that cannot be generated, only bought." }, "cols": 2, "rows": 4 } [/block] [block:api-header] { "type": "basic", "title": "IAP Menu" } [/block] Test the In-App Purchase Menu by clicking the plus button (+) next to the gems or next to the construction workers in the menu buttons on the main screen. [block:image] { "images": [ { "image": [ "https://www.filepicker.io/api/file/8C0rO9wGQGu1ZrENHxu0", "unity-iap-menu-touch-to-open.jpg", "832", "354", "#837246", "" ] } ] } [/block] [block:image] { "images": [ { "image": [ "https://www.filepicker.io/api/file/ueO3LpAPQXi10g4MOKga", "unity-mobile-app-iap-template-example.jpg", "806", "507", "#386473", "" ] } ] } [/block] [block:callout] { "type": "info", "body": "The demo IAP purchase routine is designed to use in-game currency, which you should sell in allotments. Otherwise you will want to edit the IAP script included to launch your IAP asset upon clicking the item's purchase button.", "title": "Choose Your In-App Purchase Method" } [/block] [block:api-header] { "type": "basic", "title": "How to Setup In-App Purchases" } [/block] [block:embed] { "html": "<iframe class=\"embedly-embed\" src=\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fk5pazOOnytQ%3Ffeature%3Doembed&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dk5pazOOnytQ%26feature%3Dyoutu.be&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fk5pazOOnytQ%2Fhqdefault.jpg&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=youtube\" width=\"854\" height=\"480\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>", "url": "https://www.youtube.com/watch?v=k5pazOOnytQ&feature=youtu.be", "title": "How to Create IAP - Tutorial #5", "favicon": "https://s.ytimg.com/yts/img/favicon-vflz7uhzw.ico", "image": "https://i.ytimg.com/vi/k5pazOOnytQ/hqdefault.jpg" } [/block] The **HardPriceProc.cs** IAP script included with the Starter Kit (renamed to **MenuMain/PurchaseMenu.cs** for the Pro and Complete kits) manages the menu interactions. You can customize this script to create your own menu or interactions. The script processes the total amount based on the info in **HardPrice.xml** and calculates a **totalPrice** float variable. As you add or remove items, this **totalPrice** variable is added to or subtracted from like: [block:code] { "codes": [ { "code": "// Add item price to totalPrice\ntotalPrice += float.Parse (prices [currentSelection] [\"Price\"]);\n\n// Subtract item price from totalPrice\ntotalPrice -= float.Parse (prices [currentSelection] [\"Price\"]);", "language": "csharp", "name": "Excerpt from HardPriceProc.cs " } ] } [/block] When pressing the Buy button, the **totalPrice** variable needs to reach the solution you've picked for online purchases. [Add your own IAP routine with the totalPrice variable](http://answers.unity3d.com/questions/17180/iphone-in-app-purchase-tutorial.html) or get an asset such as [Simple IAP System](https://www.assetstore.unity3d.com/en/#!/search/iap). [block:code] { "codes": [ { "code": "public void Purchase()\n\t{\n // The totalPrice (float) variable at this point contains the\n // total cost of the player's order.\n\t\t// Insert a reference to your purchase routine here using totalPrice.\n \n // ... Script source continues with increasing quanities purchased\n // ... and updating the HUD crystal, builder, and gold / mana values.\n // ... Not shown in this documentation excerpt.\n\t}", "language": "csharp", "name": "Excerpt from HardPriceProc.cs" } ] } [/block] Remember to condition the resources increase in the main interface after the online purchase has been completed, and not just opening and canceling it. [block:callout] { "type": "warning", "body": "The purchase routine in **HardPriceProc.cs** or **PurchaseMenu.cs** does not connect directly to iOS or Android IAP systems. Before publishing your game, [add your own IAP routine](http://answers.unity3d.com/questions/17180/iphone-in-app-purchase-tutorial.html) or get an asset such as [Simple IAP System](https://www.assetstore.unity3d.com/en/#!/search/iap)", "title": "In-App Purchases are Setup as a Demo" } [/block] [block:api-header] { "type": "basic", "title": "HardPrice.xml (Set in-app billing prices and quantities)" } [/block] In this file you can set the prices for each item to be purchased in the store and the amounts. - ** Builders: **Dobbit is what they're called (and the cost per additional building at one time) - **Hard-Currency:** Crystals is the name of the one hard-currency supported. - **Soft-Currency:** Gold is the first soft-currency and Mana is the second. You can rename the soft-currencies to anything you wish. [block:code] { "codes": [ { "code": "<Items> \n <Item>\n <Name>Dobbit</Name> \n <Price>1</Price>\n <PerQuantity>1</PerQuantity> \n </Item> \n <Item>\n <Name>Crystals</Name> \n <Price>0.5</Price>\n <PerQuantity>10</PerQuantity> \n </Item> \n <Item>\n <Name>Gold</Name> \n <Price>0.7</Price>\n <PerQuantity>1000</PerQuantity> \n </Item> \n <Item>\n <Name>Mana</Name> \n <Price>0.6</Price>\n <PerQuantity>500</PerQuantity> \n </Item> \n</Items>", "language": "xml", "name": "HardPrice.XML" } ] } [/block] If you want to sell additional items: 1. First add the item to **HardPrice.XML** 2. Then in **HardPriceProc.cs**(renamed to **MenuMain/PurchaseMenu.cs** for the Pro and Complete kits) increase the itemsNo variable by 1 3. Add an additional **OnBuy()** and **OnMinus()**[The methods are also named with a numerical value at the end, eg: **OnBuy3()**, **OnMinus3()**, **currentSelection = 3**, so maintain numerical sequence when adding a new method] 4. And add the item's allocation in the **Purchase()** function [block:api-header] { "type": "basic", "title": "HardPriceProc.cs References" } [/block] [block:parameters] { "data": { "h-0": "Reference", "0-0": "dobbitNo", "h-1": "Description", "1-0": "maxCrystals", "2-0": "crystals", "1-1": "**(int)** If maxCrystals is 5, and I have 3 crystals and buy 5 more; maxCrystals is increased to 8 instead of 10 (sum of max + purchase)", "2-1": "**(int)** The quantity of gems being purchased (hard currency)", "3-0": "maxStorageGold", "4-0": "gold", "0-1": "**(int)** The quantity of builders being purchased", "3-1": "**(int)** The maximum storage. Sum of Max + purchased.", "4-1": "**(int)** The quantity of gold being purchased (soft currency #1)", "5-1": "**(int)** The maximum storage. Sum of Max + purchased.", "6-1": "**(int)** The quantity of liquid mana being purchased (soft currency #2)", "5-0": "maxStorageMana", "6-0": "mana", "7-0": "totalPrice", "7-1": "**(float)** The total purchase value. Send to your IAP routine." }, "cols": 2, "rows": 8 } [/block]