Here is an example of the code I wrote. OnInitializationComplete
is executed, it starts loading that does not call any of the OnUnityAdsFailedToLoad
OnUnityAdsAdLoaded
methods. From this, I concluded that the download takes a very long time or the listener methods are not called. What to do in such a situation? Everything works fine in unity, it takes a long time to load only on android.
public TextMeshProUGUI text;
private void Start()
{
StartCoroutine(Timer());
}
private IEnumerator Timer()
{
yield return new WaitForSeconds(1);
Advertisement.Initialize("5317868", testMode: true, enablePerPlacementLoad: false, this);
}
public void OnUnityAdsAdLoaded(string placementId)
{
text.text = "Loaded";
Advertisement.Show("Interstitial_Android");
}
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
{
text.text = "UNLoaded";
}
public void OnInitializationComplete()
{
text.text = "init done";
Advertisement.Load("Interstitial_Android", this);
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
text.text = "UnINIT";
}
I tried to do it through the coroutine and without it. the result is the same. I also tried without a listener, but in this case, even the initialization fails
Loading an Ad involves a server request so it can take time.
You should probably load it in advance (for example, when your level starts) so it's ready to show when needed.
In OnUnityAdsAdLoaded
you can just set a bool m_IsReady = true;
Then, when you want to show it, you first check if (m_IsReady) Show(...)
If it's not ready, you can just skip that placement or avoid showing the option to the user (if it is a rewarded ad).