Unity 4.5, GMA SDK 2.1 Plugin, banner doesn't show (Interstitial works perfect)

315 views
Skip to first unread message

Uchiha Sasuke

unread,
Jun 10, 2014, 10:45:05 AM6/10/14
to google-adm...@googlegroups.com
Hi everyone. After a few days of experimenting, tweaking, and researching and googling I decided to ask a question here.

My banner ad won't show. "google-play-services_lib" is in Plugins/Android. It compiles fine. There are no errors, no nothing, it just doesn't show. Interstitial works perfect but the banner doesn't show. The dummy thing shows its working and showing but its actually not.
I used the demo example script and its the same situation. Doesn't work neither on my phone nor Bluestacks emulator, but interstitial works on both.

Now I just created an empty scene and made a GUI similar to the example script just for testing so I don't have to compile the entire game every time, but it doesn't work. Also made a delay of 3 sec after each request before it shows, cause it didn't wanna show without it. And made it show on start too but that doesn't work either. Anyway first things first, I wanna get the banner working. I cleaned it up a bit before posting here. Removed comments and stuff.

Its our first game we're trying to put ads in so I'm a bit confused on how it goes. xD

Unity script:

using System;
using System.Collections;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class GoogleMobileAdsTestScript : MonoBehaviour
{
 
private BannerView bannerView;
 
private InterstitialAd interstitial;
 
private AdRequest request;

 
public string bannerAdUnitID;
 
public string interstitialAdUnitID;
 
public bool isBanner;
 
public bool isInterstitial;

 
public GUIText bannerText;
 
public GUIText interstitialText;


 
IEnumerator MyBannerWait()
 
{
 
yield return new WaitForSeconds(3.0f);
 
ShowBanner();
 
}
 
IEnumerator MyInterstitialWait()
 
{
 
yield return new WaitForSeconds(3.0f);
 
ShowInterstitial();
 
}

 
void OnGUI()
 
{
 
GUILayout.BeginArea(new Rect(10,10,100,100));
 
if(GUILayout.Button("Banner"))
 
{
 
RequestBanner();
 
StartCoroutine(MyBannerWait());
 
}
 
if(GUILayout.Button("Interstitial"))
 
{
 
RequestInterstitial();
 
StartCoroutine(MyInterstitialWait());
 
}
 
GUILayout.EndArea();
 
}
 
 
void Start()
 
{
 
if(isBanner)
 
{
 
RequestBanner();
 
StartCoroutine(MyBannerWait());
 
}
 
if(isInterstitial)
 
{
 
RequestInterstitial();
 
StartCoroutine(MyInterstitialWait());
 
}
 
}

 
private void RequestBanner()
 
{
 
#if UNITY_EDITOR
 bannerAdUnitID
= "unused";
 
#elif UNITY_ANDROID
 bannerAdUnitID
= bannerAdUnitID;
 
#elif UNITY_IPHONE
 bannerAdUnitID
= bannerAdUnitID;
 
#else
 bannerAdUnitID
= bannerAdUnitID;
 
#endif

 bannerText
.text = "Requested banner...";
 bannerView
= new BannerView(bannerAdUnitID, AdSize.SmartBanner, AdPosition.Bottom);
 bannerView
.AdLoaded += HandleAdLoaded;
 bannerView
.AdFailedToLoad += HandleAdFailedToLoad;
 bannerView
.AdOpened += HandleAdOpened;
 bannerView
.AdClosing += HandleAdClosing;
 bannerView
.AdClosed += HandleAdClosed;
 bannerView
.AdLeftApplication += HandleAdLeftApplication;
 request
= new AdRequest.Builder().Build();
 
}

 
private void ShowBanner()
 
{
 bannerView
.LoadAd(request);
 bannerView
.Show();
 bannerText
.text = "Showing banner!";
 
}

 
private void RequestInterstitial()
 
{
 
#if UNITY_EDITOR
 interstitialAdUnitID
= "unused";
 
#elif UNITY_ANDROID
 interstitialAdUnitID
= interstitialAdUnitID;
 
#elif UNITY_IPHONE
 interstitialAdUnitID
= interstitialAdUnitID;
 
#else
 interstitialAdUnitID
= interstitialAdUnitID;
 
#endif
 
 interstitialText
.text = "Requested interstitial...";
 interstitial
= new InterstitialAd(interstitialAdUnitID);

 interstitial
.AdLoaded += HandleInterstitialLoaded;
 interstitial
.AdFailedToLoad += HandleInterstitialFailedToLoad;
 interstitial
.AdOpened += HandleInterstitialOpened;
 interstitial
.AdClosing += HandleInterstitialClosing;
 interstitial
.AdClosed += HandleInterstitialClosed;
 interstitial
.AdLeftApplication += HandleInterstitialLeftApplication;
 interstitial
.LoadAd(createAdRequest());
 
}
 
 
private void ShowInterstitial()
 
{
 
if (interstitial.IsLoaded())
 
{
 interstitial
.Show();
 interstitialText
.text = "Showing interstitial!";
 
}
 
else
 
{
 
print("Interstitial is not ready yet.");
 
}
 
}
 
 
#region Banner callback handlers
 
 
public void HandleAdLoaded(object sender, EventArgs args)
 
{
 
print("HandleAdLoaded event received.");
 
}
 
 
public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
 
{
 
print("HandleFailedToReceiveAd event received with message: " + args.Message);
 
}
 
 
public void HandleAdOpened(object sender, EventArgs args)
 
{
 
print("HandleAdOpened event received");
 
}
 
 
void HandleAdClosing(object sender, EventArgs args)
 
{
 
print("HandleAdClosing event received");
 
}
 
 
public void HandleAdClosed(object sender, EventArgs args)
 
{
 
print("HandleAdClosed event received");
 
}
 
 
public void HandleAdLeftApplication(object sender, EventArgs args)
 
{
 
print("HandleAdLeftApplication event received");
 
}
 
 
#endregion
 
 
#region Interstitial callback handlers
 
 
public void HandleInterstitialLoaded(object sender, EventArgs args)
 
{
 
print("HandleInterstitialLoaded event received.");
 
}
 
 
public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
 
{
 
print("HandleInterstitialFailedToLoad event received with message: " + args.Message);
 
}
 
 
public void HandleInterstitialOpened(object sender, EventArgs args)
 
{
 
print("HandleInterstitialOpened event received");
 
}
 
 
void HandleInterstitialClosing(object sender, EventArgs args)
 
{
 
print("HandleInterstitialClosing event received");
 
}
 
 
public void HandleInterstitialClosed(object sender, EventArgs args)
 
{
 
print("HandleInterstitialClosed event received");
 
}
 
 
public void HandleInterstitialLeftApplication(object sender, EventArgs args)
 
{
 
print("HandleInterstitialLeftApplication event received");
 
}
 
 
#endregion
}

Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="com.DamagedGrounds.VectorDrive" android:versionName="1.0" android:versionCode="1">
 
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
 
<!-- Google Mobile Ads Permissions -->
 
<uses-permission android:name="android.permission.INTERNET" />
 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
   
<!-- meta-data tag for Google Play services -->
   
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
 
<activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
   
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
     
<intent-filter>
       
<action android:name="android.intent.action.MAIN" />
       
<category android:name="android.intent.category.LAUNCHER" />
     
</intent-filter>
   
</activity>
   
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
   
</activity>
   
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
     
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
     
<meta-data android:name="android.app.lib_name" android:value="unity" />
   
</activity>
   
<activity android:name="com.unity3d.player.VideoPlayer" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
   
</activity>
   
<!-- Google Mobile Ads Activity -->
 
<activity android:name="com.google.android.gms.ads.AdActivity"
             
android:label="@string/app_name"
             
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
   
</activity>
 
</application>
 
<uses-feature android:glEsVersion="0x00020000" />
 
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
</manifest>


Any ides? :S

Thanks! 
Message has been deleted

Uchiha Sasuke

unread,
Jun 10, 2014, 11:42:59 AM6/10/14
to google-adm...@googlegroups.com
Oops forgot to add a part of code revolving interstitial ad, but that's not the issue here anyway. Its the banner ads that refuse to show up. xD

Uchiha Sasuke

unread,
Jun 10, 2014, 3:42:11 PM6/10/14
to google-adm...@googlegroups.com
I fixed it. Something was off with my demo script, outdated I think, so I used the script from the Hello World example, and deleted everything admob related and imported again, and it worked so I just suited the demo script to my need. 

One thing tho. The banners don't always load. The first time it did but the second time I played a few mins without the banner ad ever showing. Interstitial works 95% of the time.

And I'm confused on when should I request, show, hide, and destroy? 

Right now I'm requesting on the splash screen, showing interstitial and banners when menu loads (interstitial doesn't load first time), requesting when gameplay scene is loaded, and showing banners when the game is paused.

Eric Leichtenschlag

unread,
Jun 11, 2014, 7:39:26 PM6/11/14
to google-adm...@googlegroups.com
AdMob has pretty high fill rate, so fill shouldn't be the issue. In your HandleAdFailedToLoad method, if you check AdFailedToLoadEventArgs.Message, what is the error reason for why the banner is failing? (See https://github.com/googleads/googleads-mobile-plugins/blob/master/unity/README.md#ad-events for more info on setting the AdFailedToLoad event).

As for show/hide/destroy, you can show and hide whenever you like, but make sure to call destroy before requesting another banner, so the plugin can free the memory on the iOS side.

Thanks,
Eric

Uchiha Sasuke

unread,
Jun 11, 2014, 8:05:59 PM6/11/14
to google-adm...@googlegroups.com
Right, banners are working almost as much as interstitials now. I think it might be lack of ads that target my country. Also I forgot to mention I'm doing this on android not iOS, can't afford a Mac and iPhone yet. xD

I have the error checks set up but where do I look at the logs on android? Or do I just setup so it shows the report in game?

I'm satisfied and excited that everything is quite simple to do, just import and use, I only lost days because I was using outdated stuff I think. And I also set up Google Play Achievements and Leaderboards in a few hours. xD 

I have a couple more Qs. My banner's don't seem to be refreshing every 60 sec like its set up in AdMob, any idea why? And do you know where can I ask about Play Games Plugin for Unity? I wanna know how can I check if a user is logged in or achivement made, ano other stuff.

Thanks!

Eric Leichtenschlag

unread,
Jun 12, 2014, 2:24:29 PM6/12/14
to google-adm...@googlegroups.com
It's possible that the ad is refreshing with the same ad again. Or if you're hiding the ad, it'll skip the refresh cycle at refresh time because the ad isn't currently visible. If the former is the issue, you can listen to the AdLoaded event to see if an ad refreshed. If the latter is true, Android LogCat will log something like "Ad is not visible, not refreshing ad".

I believe Google Play Games services does support on StackOverflow. From the Plugin's README, you can add the plugin owner on G+ and bug him to look at your StackOverflow question.

Thanks,
Eric

Uchiha Sasuke

unread,
Jun 12, 2014, 2:44:03 PM6/12/14
to google-adm...@googlegroups.com
Haha thanks! I think the ad is refreshing with the same ad sometimes, cause its working now but not always, its definitely the lack of ads targeting my stupid country. Its all working good now, I even integrated Everyplay plugin in the game. :)
Reply all
Reply to author
Forward
0 new messages