The Final Boss of Unity: Ads and IAP.

I thought I'd encountered the most difficult things Unity could throw at me... Shaders were confusing, I-Enumerators took a while to understand and integrating audio took a lot longer than expected.

It all palled in comparison too getting started on in-app-purchases. 

Last time, I detailed how the player has 5 lives that take half an hour to recharge. So before I got into it. I decided to make  splash screen for when the player attempted to play the game without any lives. 

Originally I had some over complicated screen, telling the player about all the cool things they could buy in the shop. I realised it looked to cluttered and was more than likely going to drive the player away. I went with this cool graphic, with a nice crying monkey animation. Since the only way out of this screen is to exit through the shop, I'm counting on the player seeing all the shop has to offer. The diagram indicates that the player can watch a video to get a free life.

I decided to make the free-life-for-a-video function first. To do this I had to integrate Unity Ads. Normally done through the service panel, i struggled to do it the way the documentation suggested. At this level, i found Unity's usually helpful documentation and guides were actually quite sparse. The same with In App Purchases which I'll cover later. I relied quite heavily on reading the forums and learning from my mistakes. In the end, I downloaded the separate Unity Ads SDK 2.0 instead of using ads through the services panel. I attached this script to my GameMaster object to initialise ads, I found it somewhere on the internet, don't ask me where.

using UnityEngine;
using UnityEngine.Advertisements;

public class UnityAdsInitializer : MonoBehaviour
    private string
    androidGameId = "1466923",
    iosGameId = "1466924";

    private bool testMode;

    void Start ()
        string gameId = null;

        #if UNITY_ANDROID
        gameId = androidGameId;
        #elif UNITY_IOS
        gameId = iosGameId;

        if (Advertisement.isSupported && !Advertisement.isInitialized) {
            Advertisement.Initialize(gameId, testMode);

Once I had this in, I made sure to enable ads in the service panel but uncheck the box marked "Enable Built in Ads Extension". I was then able to use reward ads in the game, granting the player a free life if they watched a video.

Next up, I had to set up In-App-Purchases themselves. I began by looking at some daunting tutorials. It straight away seemed that it would be completely beyond me. Luckily I stumbled across one of Unity's newer features; codeless IAP. This feature is exactly what it sounds like; it allows you to intergrate IAP without writing any code except that of the product itself.

The codeless IAP was worryingly simple. All the comments I had read online indicated that it was temperamental  and only worked under certain conditions. Perhaps it was because I was working with 5.6 (which wasn't mentioned at all) that things went well for me. As I mentioned earlier, At this level, the helpfulness of Unity's documentation and guides drops off quite a bit. I'm not sure if it's because 5.6 has just come out recently and everyone is catching up to it, or if it's because 5.6 works perfectly and no one has reported any bugs for it yet.

eitherway, I had a nice shop set up. I just had to make the graphics for it. I tried to keep the simplicity of the options menu going, but the shop just has too much information to give. The in built IAP button of the codeless IAP has a beautiful feature that allows you to link text files to the title, description and price of a product. This means different translations and prices can be set for a product and made region dependent. Unity will simply grab the relevant data from which ever app store you choose to use, then drag it down and populate the text boxes with the correct information. This removes the need to ensure that the shop is language neutral, something I have tried to do throughout this project. I can simply upload translations within the Appstore in question, and Unity will do the rest.

I looked at a lot of other game IAP stores and eventually came up with this design.

I used a scroll rect to fit all the info on one screen without it looking overcrowded. Horizontal and vertical layout components keep everything in place. The back button is kept blue to be easily identifiable. Similarly, the purchase button is green so it sticks out and is easily noticeable amongst the brown background.

And that was it. All thats left to do is tidy up the project a bit. Namely:

  1. delete all the debug.log notes I forgot about.
  2. write a better theme tune with bosca ceoil.
  3. delete all redundant scripts.
  4. redo the bloody awful snakes head sprite.

It's not much. Of course there will be lots of testing to be done. Which I still need to figure out how to handle. After that of course, Is the Mammoth of Marketing. Which i'll probably blog my way through as well. 

As usual, share with your friends if you found it interesting.