Hello everyone, I have a problem.
I am using unity2021.3.11f1c2, and Mediation version is 1.0.4.
I enabled test mode on dashboard, and I can see the test ads in the editor, but I can’t see the test ads on Android phone, I printed the relevant logs and found that Android can initialize, but the Load failed, prompting no line item filled.
I’m using Interstitial ads, and I haven’t added a Store ID yet because my Google Store hasn’t been approved yet.
I thought it was because the keywords “await”, “async” were not supported in Android, but after switching to Coroutine, I still can’t see the test ads.
The strangest thing is that the game I submitted to Google for review, I see real ads in Google’s auto-test screenshot.
This is the code I am currently using, and I believe I have written it correctly.And I make sure the Android game id and unit id in my code is the same as the dashboard.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Services.Core;
using Unity.Services.Mediation;
using System;
public class AdvertisementsManager : MonoBehaviour
{
private readonly string gameId = "xxxxxxx";
private readonly string adUnitId = "Resurrection";
public static AdvertisementsManager Instance;
private IInterstitialAd interstitialAd;
private WaitForSeconds waitTime = new(1);
private bool isInitialized;
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
}
void Start()
{
DontDestroyOnLoad(gameObject);
StartCoroutine(InitAd());
StartCoroutine(KeepCheckLoading());
}
private IEnumerator InitAd()
{
InitializationOptions options = new();
options.SetGameId(gameId);
UnityServices.InitializeAsync(options);
while (UnityServices.State != ServicesInitializationState.Initialized)
{
yield return waitTime;
}
interstitialAd = MediationService.Instance.CreateInterstitialAd(adUnitId);
interstitialAd.OnLoaded += InterstitialAd_OnLoaded;
interstitialAd.OnFailedLoad += InterstitialAd_OnFailedLoad;
interstitialAd.OnShowed += InterstitialAd_OnShowed;
interstitialAd.OnFailedShow += InterstitialAd_OnFailedShow;
interstitialAd.OnClosed += InterstitialAd_OnClosed;
print("Initialized");
isInitialized = true;
}
private IEnumerator KeepCheckLoading()
{
while (true)
{
yield return waitTime;
if (!isInitialized)
continue;
if (interstitialAd.AdState == AdState.Unloaded)
{
LoadAd();
}
}
}
public void LoadAd()
{
interstitialAd.LoadAsync();
}
public void ShowAd()
{
if (interstitialAd.AdState == AdState.Loaded)
interstitialAd.ShowAsync();
}
private void InterstitialAd_OnLoaded(object sender, EventArgs e)
{
print("Loaded");
}
private void InterstitialAd_OnShowed(object sender, EventArgs e)
{
print("Showed");
}
private void InterstitialAd_OnClosed(object sender, EventArgs e)
{
print("Closed");
if (BaseGameManager.Instance)
BaseGameManager.Instance.CloseGameLostPage();
LoadAd();
}
private void InterstitialAd_OnFailedLoad(object sender, LoadErrorEventArgs e)
{
print("OnFailedLoad:" + e.Message);
}
private void InterstitialAd_OnFailedShow(object sender, ShowErrorEventArgs e)
{
print("OnFailedShow:" + e.Message);
}
}