- Home /
Admob ads not showing in the mobile device
so this is being a huge problem to me from couple of days i made a game and very thing works fine i added the google mobile sdk and the dummy ads loaded in the editor but when installed it on android it no longer shows i downloaded many example project but the same thing i just want to know that maybe i am missing out on something important.any help will be appreciated here is my code :
using System; using UnityEngine; using GoogleMobileAds; using GoogleMobileAds.Api;
// Example script showing how to invoke the Google Mobile Ads Unity plugin. public class ads : MonoBehaviour { void Start () { RequestBanner (); }
private void RequestBanner()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Create a 320x50 banner at the top of the screen.
BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the banner with the request.
bannerView.LoadAd(request);
}
}
Answer by vas1990 · Apr 11, 2017 at 10:27 AM
You probably should call bannerView.Show() at the end
Answer by codorpsgames · Sep 01, 2017 at 09:20 AM
unlike banner ads, interstitial ads must be explicitly shown. Therefore explicitly checking if the instance of the interstitial ad is loaded inside the Start() method is too fast hence will not show upon call. Instead, load the interstitial ad on start() method then check if it is loaded on update(), then show i.e
void Start () {
RequestInterstitial();
}
// Update is called once per frame
void Update () {
if (interstitial.IsLoaded())
{
interstitial.Show();
}
if (Input.GetKeyDown(KeyCode.Escape))
{
SceneManager.LoadScene("mainmenu");
}
}
public void RequestInterstitial()
{
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "INSERT_ANDROID_INTERSTITIAL_AD_UNIT_ID_HERE";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
This one worked like a charm mate!