When in the Unity editor, test ads (Unity Ads) run fine. However, after publishing (I had assumed all was well), I discovered no ads were playing, causing players to get stuck in the preloading scene (I built a “preloading” scene before the first level/scene where I placed a script that runs the ad. When the ad is done, the first scene is loaded).
However, it seems the player was getting stuck in the preloading scene because no ad was played. I patched an update to the ad script, which loads the first scene in the case the ad fails. However, the problem remains that no ads play, despite working in the editor.
I am including the script I am using to run the ads in the preloading scene. I am unsure what to do as I am uncertain whether I am doing something wrong, if the Unity Ads servers are screwing up, or something else.
Here is the script being used for playing the ad, in it’s entirety:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
using UnityEngine.SceneManagement;
public class PlayAd : MonoBehaviour
{
public static PlayAd Instance { set; get; }
public void Start()
{
Instance = this;
DontDestroyOnLoad(gameObject);
Advertisement.Initialize("1370212", true);
var showOptions = new ShowOptions
{
resultCallback = HandleShowResult
};
if (Advertisement.IsReady())
{
Advertisement.Show();
}
}
public string LoadLevel
{
get
{
return loadLevel;
}
set
{
loadLevel = value;
}
}
[SerializeField] private string loadLevel;
private void HandleShowResult(ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
LevelLoad();
break;
case ShowResult.Skipped:
break;
case ShowResult.Failed:
break;
}
}
public void LevelLoad()
{
SceneManager.LoadScene(LoadLevel);
}
}