Okay, so I’ve looked up tutorial after tutorial, and the Unity docs, and other forums, I even tried Chat GPT. My ads are not showing, and I do not understand why. I have a script that Initilizes the ads, and a script to show the ads every 5 levels (scene loads in this case.)
Initilizer:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
{
[SerializeField] string _androidGameId;
[SerializeField] string _iOSGameId;
[SerializeField] bool _testMode = true;
private string _gameId;
void Awake()
{
InitializeAds();
}
public void InitializeAds()
{
#if UNITY_IOS
_gameId = _iOSGameId;
#elif UNITY_ANDROID
_gameId = _androidGameId;
#elif UNITY_EDITOR
_gameId = _androidGameId; //Only for testing the functionality in the Editor
#endif
if (!Advertisement.isInitialized && Advertisement.isSupported)
{
Advertisement.Initialize(_gameId, _testMode, this);
}
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
}
and then to show the ads:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class Interstitialads : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
{
[SerializeField] string _androidAdUnitId = "Interstitial_Android";
[SerializeField] string _iOsAdUnitId = "Interstitial_iOS";
string _adUnitId;
static int loadCount = 0;
void Start()
{
if (loadCount == 5)
{
loadCount = 0;
ShowAd();
}
else
{
loadCount += 1;
}
}
public void ShowAd()
{
Advertisement.Show(_adUnitId, this);
}
void Awake()
{
// Get the Ad Unit ID for the current platform:
_adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsAdUnitId
: _androidAdUnitId;
LoadAd();
}
// Load content to the Ad Unit:
public void LoadAd()
{
// IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
Debug.Log("Loading Ad: " + _adUnitId);
Advertisement.Load(_adUnitId, this);
}
// Show the loaded content in the Ad Unit:
public void OnUnityAdsAdLoaded(string placementId)
{
}
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
{
}
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
{
}
public void OnUnityAdsShowStart(string placementId)
{
}
public void OnUnityAdsShowClick(string placementId)
{
}
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
{
}
}