Hello Everyone,
I installed Unity Ads (not having a Google Play Store account), in the editor, banners say “This would be a banner”, rewarded and skippable ads pop up and say “This screen would be your Ad Unit”. But when building the app and apk, nothing happens, banners are not coming up, ad units are not popping up.
Is it because I didn’t open a play store account?
Thanks in advance!
Could you please take a look at my script. Why can’t I see the ads when I build the game?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class AdsManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
#if UNITY_ANDROID
string gameID = "5657197";
string bannerAd = "Banner_Android";
string interstitialAd = "Interstitial_Android";
string rewardedAd = "Rewarded_Android";
#else
string gameID = "5657196";
string bannerAd = "Banner_iOS";
string interstitialAd = "Interstitial_iOS";
string rewardedAd = "Rewarded_iOS";
#endif
void Start()
{
Advertisement.Initialize(gameID, true, this);
}
public void ShowBanner()
{
Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
Advertisement.Banner.Show(bannerAd);
}
public void HideBanner()
{
Advertisement.Banner.Hide();
}
IEnumerator RepeatShowBanner()
{
yield return new WaitForSeconds(1);
ShowBanner();
}
public void PlayAd()
{
Advertisement.Show(interstitialAd, this);
}
public void PlayRewarded()
{
Advertisement.Load(rewardedAd, this);
Advertisement.Show(rewardedAd, this);
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.LogError($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
public void OnUnityAdsAdLoaded(string adUnitId)
{
Debug.Log($"Ad loaded: {adUnitId}");
}
public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
{
Debug.LogError($"Failed to load ad: {adUnitId} - {error.ToString()} - {message}");
}
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
if (adUnitId.Equals(rewardedAd))
{
Time.timeScale = 1; // Resume the game when the ad is closed
}
if (adUnitId.Equals(interstitialAd))
{
Time.timeScale = 1; // Pause the game when the interstitial ad starts
}
}
public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
{
Debug.LogError($"Ad show failed: {adUnitId} - {error.ToString()} - {message}");
if (adUnitId.Equals(rewardedAd))
{
Time.timeScale = 1; // Ensure the game is resumed even if the ad fails
}
if (adUnitId.Equals(interstitialAd))
{
Time.timeScale = 1; // Pause the game when the interstitial ad starts
}
}
public void OnUnityAdsShowStart(string adUnitId)
{
if (adUnitId.Equals(rewardedAd))
{
Time.timeScale = 0; // Pause the game when the rewarded ad starts
}
if (adUnitId.Equals(interstitialAd))
{
Time.timeScale = 0; // Pause the game when the interstitial ad starts
}
}
public void OnUnityAdsShowClick(string adUnitId)
{
// Optional: Handle ad click event
}
}
Are there any error messages when you attempt to show ads?
Initialization has been completed before Load()?
Loading has been completed before Show()?