I’ve been trying for days to figure out how to implement admob ads into a unity project with little to no luck and it has become infuriating. the code below is a (verbatim) copy of the Admob getting started video here: Unity and AdMob Rewarded Video - Mobile Ads Garage #10 - YouTube
(The AdUnitId’s are the provided by google Id’s for running test ads.)
GoogleMobileAdsDemoScript.cs :
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
using System;
public class GoogleMobileAdsDemoScript : MonoBehaviour {
private RewardBasedVideoAd rewardBasedVideoAd;
public void Start() {
rewardBasedVideoAd = RewardBasedVideoAd.Instance;
// Called when an ad request has successfully loaded.
rewardBasedVideoAd.OnAdLoaded += HandleRewardBasedVideoLoaded;
// Called when an ad request failed to load.
rewardBasedVideoAd.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
// Called when an ad is shown.
rewardBasedVideoAd.OnAdOpening += HandleRewardBasedVideoOpened;
// Called when the ad starts to play.
rewardBasedVideoAd.OnAdStarted += HandleRewardBasedVideoStarted;
// Called when the user should be rewarded for watching a video.
rewardBasedVideoAd.OnAdRewarded += HandleRewardBasedVideoRewarded;
// Called when the ad is closed.
rewardBasedVideoAd.OnAdClosed += HandleRewardBasedVideoClosed;
// Called when the ad click caused the user to leave the application.
rewardBasedVideoAd.OnAdLeavingApplication += HandleRewardBasedVideoLeftApplication;
}
public void OnGUI()
{
GUIStyle style = new GUIStyle();
Rect rect = new Rect(0, 0, Screen.width, Screen.height);
style.alignment = TextAnchor.LowerRight;
style.fontSize = (int)(Screen.height * 0.06f);
style.normal.textColor = new Color(0f, 0f, .5f, 1f);
GUI.skin.button.fontSize = (int)(0.035f * Screen.width);
float buttonWidth = 0.35f * Screen.width;
float buttonHeight = 0.15f * Screen.height;
float columnOnePosition = 0.1f * Screen.width;
Rect requestRewardRect = new Rect(columnOnePosition, 0.1f * Screen.height, buttonWidth, buttonHeight);
Rect showRewardRect = new Rect(columnOnePosition, 0.3f * Screen.height, buttonWidth, buttonHeight);
if (GUI.Button(requestRewardRect, "Request
Rewarded Video"))
{
LoadRewardBasedAd();
}
if (GUI.Button(showRewardRect, "Show
Rewarded Video"))
{
ShowRewardBasedAd();
}
}
private void LoadRewardBasedAd() {
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/7325402514";
#endif
rewardBasedVideoAd.LoadAd(new AdRequest.Builder().Build(), adUnitId);
}
void ShowRewardBasedAd()
{
if (rewardBasedVideoAd.IsLoaded())
{
rewardBasedVideoAd.Show();
}
else print("Ad not ready!");
}
public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoLoaded event received");
}
public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
MonoBehaviour.print(
"HandleRewardBasedVideoFailedToLoad event received with message: "
+ args.Message);
}
public void HandleRewardBasedVideoOpened(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoOpened event received");
}
public void HandleRewardBasedVideoStarted(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoStarted event received");
}
public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoClosed event received");
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
string type = args.Type;
double amount = args.Amount;
MonoBehaviour.print(
"HandleRewardBasedVideoRewarded event received for "
+ amount.ToString() + " " + type);
}
public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args)
{
MonoBehaviour.print("HandleRewardBasedVideoLeftApplication event received");
}
}
Additionally, I have:
- downloaded the most recent package from their GitHub repo
- force-resolved Android dependencies and updated the version via unity menu options.
- Updated my version of Unity ( to 2017.4.3f1 )
- Run my Android in development build
- Tried implementing other ad types such as banner.
- Run my Android Build in ADB Logcat
When ran in adb using Adb Logcat -s Unity in the console, I get this error message though, as if the ad continuously fails to load and instead throws a timeout error. (I’ve tried many times to get it to work in the case that it could just be a timeout error, but no luck )
HandleRewardBasedVideoFailedToLoad event received with message: Internal error
06-29 16:14:50.664 31067 31067 I Unity : UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
06-29 16:14:50.664 31067 31067 I Unity : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
06-29 16:14:50.664 31067 31067 I Unity : UnityEngine.Logger:Log(LogType, Object)
06-29 16:14:50.664 31067 31067 I Unity : UnityEngine.Debug:Log(Object)
06-29 16:14:50.664 31067 31067 I Unity : UnityEngine.MonoBehaviour:print(Object)
06-29 16:14:50.664 31067 31067 I Unity : GoogleMobileAdsDemoScript:HandleRewardBasedVideoFailedToLoad(Object, AdFailedToLoadEventArgs) (at C:\
Does anyone have an idea of what I must be doing wrong here? any guidance would be greatly appreciated!
Also, if anyone is wondering about the scene, It is a simple scene with only a main camera and the GoogleMobileAdsDemoScript.cs attached as a component.