Keep in mind, picture ads are still in beta. Which means there is limited fill for English speaking countries, and in most cases no fill for non-English speaking countries.
You can still test picture ad functionality regardless of fill by enabling test mode:
public string gameID;
public bool disableTestMode;
void Awake ()
{
bool enableTestMode = Debug.isDebugBuild && !disableTestMode;
Debug.Log(string.Format("Initializing Unity Ads for game ID {0} with test mode {1}...",
gameID, enableTestMode ? "enabled" : "disabled"));
Advertisement.Initialize(gameID,enableTestMode);
}
Having gameID and disableTestMode as public variables makes it easy to set them from the inspector. During development, you always want to be initializing Unity Ads with test mode enabled. With the above code, test mode will be enabled if Development Build is enabled in Build Settings. However, you can force production ads to be shown instead of test ads by checking disableTestMode.
When you’re ready to publish your game, simply disable Development Build and test mode will be disabled. This way you don’t accidentally ship your game with test mode enabled, which would only show test ads and not generate any revenue.
To show picture ads, Unity Ads needs to be both initialized and ready to show ads:
if (Advertisement.isInitialized &&
Advertisement.isReady("pictureZone"))
{
Advertisement.Show("pictureZone");
}
Something like this will allow you to show an ad shortly after the scene loads:
public string zoneID = "pictureZone";
public float timeout = 15f;
private float _startTime = 0f;
private float _yieldTime = 1f;
// A return type of IEnumerator allows for the use of yield statements.
// For more info, see: http://docs.unity3d.com/ScriptReference/YieldInstruction.html
IEnumerator Start ()
{
// Set zoneID to null if string is empty.
// When zoneID value is null, the default zone is used.
if (string.IsNullOrEmpty(zoneID)) zoneID = null;
// Check to see if Unity Ads is initialized.
// If not, wait a second before trying again.
do yield return new WaitForSeconds(_yieldTime);
while (!Advertisement.isInitialized);
Debug.Log("Unity Ads has finished initializing. Waiting for ads to be ready...");
// Set a start time for the timeout.
_startTime = Time.timeSinceLevelLoad;
// Check to see if Unity Ads are available and ready to be shown.
// If not, wait a second before trying again.
while (!Advertisement.isReady(zoneID))
{
if (Time.timeSinceLevelLoad - _startTime > timeout)
{
Debug.LogWarning("The process for showing ads on load has timed out. " +
"Ad not shown.");
// Break out of both this loop and the Start method; Unity Ads will not
// be shown on load since the wait time exceeded the time limit.
yield break;
}
yield return new WaitForSeconds(_yieldTime);
}
Debug.Log("Ads are available and ready. Showing ad now...");
// Show ad after Unity Ads finishes initializing and ads are ready to show.
Advertisement.Show(zoneID);
}
Additional code examples and demo scene are available here.