-
Notifications
You must be signed in to change notification settings - Fork 7
UnityAdsHelper Initialization
The UnityAdsHelper.Initialize()
method configures and initializes Unity Ads by referencing the settings stored in an instance of UnityAdsSettings, a ScriptableObject. By default, the UnityAdsSettings asset can be found in the Resources directory. You can view the UnityAdsSettings asset in the Inspector by selecting it directly, or by selecting Edit > Unity Ads Settings from the Unity Editor menu. Selecting this menu item will create the UnityAdsSettings asset if it does not already exist in your project.
The option Enable Test Mode is enabled by default in UnityAdsSettings. While developing and testing your game, you should always leave Test Mode enabled. The only time it's appropriate to disable Test Mode is in cases where you are attempting to test the functionality of production ad campaigns, instead of just test ad campaigns.
Note: Development Build must be enabled in Build Settings in order to initialize Unity Ads with Test Mode enabled. This is a feature of the UnityAdsHelper script, and is intended to help prevent from accidentally releasing a final build with Test Mode still enabled.
One of the nice things about the UnityAdsHelper script is that it can be used to initialize Unity Ads in one of two ways:
- by calling
UnityAdsHelper.Initialize()
from a script within your project, - or simply by adding the UnityAdsHelper script to a new GameObject in your main scene.
For the purposes of this example, let's initialize Unity Ads by calling UnityAdsHelper.Initialize()
.
C# Example – UnityAdsExample.cs
using UnityEngine;
using System.Collections;
public class UnityAdsExample : MonoBehaviour
{
void Start ()
{
UnityAdsHelper.Initialize();
}
}
JavaScript Example – UnityAdsExample.js
#pragma strict
public class UnityAdsExample extends MonoBehaviour
{
function Start () : void
{
UnityAdsHelper.Initialize();
}
}
Now let's add the script to your scene. Create a new GameObject in your main scene and rename it to UnityAdsExample. Then add the UnityAdsExample script to it.
The UnityAdsHelper should only be initialized once within your game, ideally when your game first starts up. In any case, the UnityAdsHelper is capable of managing its own instances, and persists across scene loads. So there will only ever be one UnityAdsHelper at a time in your game, and Unity Ads will only be initialized once.
One thing to consider when designing your game with Unity Ads is that you don't always have to initialize Unity Ads at the start of your game.
For instance, if you've designed your game to delay the showing of ads until after the user has had time to learn the rules of gameplay and progress through a few levels, it may take a few game sessions before they reach a point where they would start seeing ads.
In this case, you could hold off on initializing Unity Ads until after they've crossed this threshold. Keep in mind though, Unity Ads does take several seconds to initialize and cache the assets necessary to show an ad. You should therefore allow sufficient time for Unity Ads to finish initializing before attempting to show an ad.