Getting Started With Game Framework for Unity – Part 4 – Unlocking, Level Configuration and In App Purchase 2


Skill level: Basic knowledge of Unity
Tutorial time: 10 minutes
Implementing in your projects: 5 minutes

Part 1 – The Basics, Audio, Settings and Localisation
Part 2 – Level Setup and Selection
Part 3 – Game Loop, Score and Coins
Part 4 – Unlocking, Level Configuration and In App Purchase
Part 5 – Applying a Theme
Part 6 – Worlds
Part 7 – GameItems, Lives, Health and Stars
Part 8 – Messaging essentials
Part 9 – A Better Game

In the proceeding parts of this tutorial we setup the basics of our game. There are still however a few bits that we need to complete so everything works as expected and also we can start adding some powerful new features.

Unlocking Levels

Until now we have used completion as a way of unlocking levels. We will now show another common method that requires the user to collect coins to unlock. First go to the Cheat Functions windows and under the General tab in the Preferences section click Reset to clear all saved preferences. Run the game and check that in the Menu scene only the first level is unlocked.

Next on the GameManager component on _GameScope change Level Setup to Coins. We will leave the number of coins needed to unlock each level to 10. If you created a prefab of this then Apply the changes by clicking the Apply button at the top of the inspector so the prefab is updated.

If you now run and navigate to the Menu scene you will see that locked buttons also show how many coins are needed to unlock each level. If you use the Cheat Window to set the players coins to both 0 and 10 (or more), you should see the number of coins text on the level buttons changes color to indicate when they can be unlocked.

We have 10 levels, but only 1 is currently unlocked. There are several different possibilities that we can setup for how a user can coin unlock new levels including both clicking on an item and a separate unlock button. Here we will use an unlock button and a random unlock mode so a level is picked at random to unlock.

On the Menu scene under Canvas add a new button (GameObject Menu->UI->Button). Rename it to UnlockButton and position it under where the level buttons would appear using by setting the following values.

Change the Text gameobjects Font Size to 50 so it is more visible.

Onto UnlockButton add the UnlockLevelButton component (Add Component->Game Framework->GameStructure->Levels). The default unlock mode is RandomAll where a random level is chosen from all those that have an unlock value below the current coin value (even unlocked ones). This means that sometimes a user won’t open a new level as the chosen level will already be unlocked. A benefit of this is that they don’t get everything too quickly however it can be frustrating if they never unlock anything. On the UnlockLevelButton component you can set Max Failed Unlocks to 0 if you want them to always open a level (equivalent to Random Locked mode), or some lower value (e.g. 3) to have them always unlock a level after that number of attempts.

Run the game and use the Cheat Functions to increase and reset the score. You will see the Unlock button becomes available when it is possible to unlock a level and that clicking on this unlocks a new level or tells you if the level was already open. Animated unlock effects are also supported when combined with the Beautiful Transitions asset and easy to add.

Unlock Dialog

As a small improvement, drag the AttentionLegacy animation from \FlipwebApps\GameFramework\Animations\General onto UnlockButton and also set UnlockButton->RectTransform->Pivot X and Y to 0.5 run again and notice the animation to gain attention.

Currently all of the levels have a default unlock value of 10 as we setup in GameManager. We will shortly look at how we can change this.

The level select page is also a great candidate for adding Free Prize functionality. Check out the link for more details.

In App Purchase

In App Purchase is very easy to add, and builds upon the standard Unity IAP offering whilst at the same time taking away the need for additional coding. There is built in support for unlocking Levels, Characters and Game Unlock (e.g. remove adverts) and it is easy to extend and add your own items for purchase.

We don’t discuss here setting up Unity IAP or configuring in iTunes Connect or Google Play as it is assumed that you know how to add products and other configuration in those places. Even without configuring these you can still run this part of the tutorial as it is possible to simulate and test IAP through the Cheat Functions Window in the Unity Editor without setting up a store backend.

To add IAP, first enable Unity IAP in the editor through the Services window. Next drag the PaymentManager (Add Component->Game Framework->Billing) onto _GameScope and click Apply to update the prefab (note: PaymentManager will only show up if you have enabled IAP).

To PaymentManager->Products add all the IAP identifiers that you will use (this is the same as you will need to register in iTunes Connect / Google Play). For levels this should be in the format unlock.level.[Level Number] e.g unlock.level.2.

IAP Setup

Simple as that. Now, when a user clicks or taps on a locked level, they will now be given the option to pay to open it. You can simulate purchases through the Cheat Functions window as discussed further in the in app purchase documentation.

Billing Cheat Window

Per Level Configuration

So far we have seen how to configure each levels name, description and image. GameItem configuration files give us a lot more control of these and a lot of other options and can even be extended to add your own custom properties, configuration and code.

Start by clicking on the Resources\Level folder that you created previously and select Create->Game Framework->Level, rename the newly created item to Level_1 to associate it with the level numbered 1 and then select it to view it’s properties.

levelconfiguration

In the newly created configuration file we can set many options including a fixed (non-localised) name and description or an alternative localisation key to use, the value needed to unlock this item, associated prefabs and sprites and various level specific properties.

For this first configuration file set the Name to the localised key that we already create for the first levels name by clicking on the globe icon and entering L1.Name into the text field. You should see that the display is updated with the text from the localisation file. Also enable the Start Unlocked option as we want this first level to be unlocked when the user starts the game for the first time.

localisedname

Now duplicate the configuration to create a copy named Level_2. Set the name to the localised key L2.Name. This time deselect the Start Unlocked option as we want the user to have to unlock these items. Enable instead Unlock With Coins and set Value To Unlock to 5.

unlockwithcoins

Duplicate the Level_2 item for all our levels (upto Level_10) giving different unlock values (e.g. multiples of 5 such as 5, 10, 15, …).

On _GameScope->GameManager change the Level Setup mode to From Resources so that the new configuration files are loaded.

Run the game and you will now see that the level selection screen is updated with our new unlock values.

We will revisit the level configuration later, but there are many powerful options that you can setup here. Take a look at the Game Structure documentation for further information.

Wrapup

We now have most bits in place for our game, and setting this up has not taken long. In the next part of this getting started series, we will look at how we can make our game more visually pleasing by using the themes that are included in the Extras Bundle. Even if you don’t have the extras bundle it is worth reading this tutorial to understand how you can provide your own customisations.

If you like the framework then please consider downloading the extras bundle for access to the tutorial files and lots of other useful samples and assets. This also helps support our efforts to develop and maintain this framework.

If you have any questions or feature requests then let us know below.

Further Information


2 thoughts on “Getting Started With Game Framework for Unity – Part 4 – Unlocking, Level Configuration and In App Purchase

  • Muckel

    Great,
    but don’t trust Unity iAP.
    It’s like you tell everything you own to the Unity crew… maybe later they come back because they can track you because of Unity iAP!!!
    That is not nice busyness and i never want that other know how much and where i sell my stuff… NEVER!!!!
    So be careful if you implement Unity iAP & Unity Analytics… it’s like you tell Google how much you earn and from who etc…
    NO NO NO you never should do that…
    YOU Know what privacy is ?

    • admin Post author

      Hi. IAP support in the framework can be enabled / disabled, and builds upon the new Unity IAP for simplicity and to avoid the need for other assets. Any data collected by Unity would be covered by EU (and other) privacy laws and their own privacy policy (although it is pretty vague in the details of what they collect for IAP) so can hopefully be trusted.

Comments are closed.