Admob 2018 package for Unity (3.15.1) not showing ads in android mobile devices (banner, interstitial, rewarded video etc.)C# method failing to function for no known reasonUnity3d Admob Reward Based Video errorAdmob unity rewarded videos not workingHow to show admob interstitial and reward ads in Unity game?Reward video not showing, and not giving reward. Unity 3dIntegrate admob Rewarded video in unityAdmob shows banner ad, but doesn't show video (Rewarded ads)how to store into a session and display current users informationUnity Admob Interstitial Ads Not ShowingAdMob/Unity - Rewarded Video are not showing
Do Iron Man suits sport waste management systems?
Am I breaking OOP practice with this architecture?
Why didn't Boeing produce its own regional jet?
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
Send out email when Apex Queueable fails and test it
Why is the sentence "Das ist eine Nase" correct?
Implication of namely
Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?
How do conventional missiles fly?
How to remove border from elements in the last row?
Are British MPs missing the point, with these 'Indicative Votes'?
Calculate the Mean mean of two numbers
What's the meaning of "Sollensaussagen"?
Avoiding the "not like other girls" trope?
Can someone clarify Hamming's notion of important problems in relation to modern academia?
What is required to make GPS signals available indoors?
Can I hook these wires up to find the connection to a dead outlet?
Is it possible to map the firing of neurons in the human brain so as to stimulate artificial memories in someone else?
My ex-girlfriend uses my Apple ID to log in to her iPad. Do I have to give her my Apple ID password to reset it?
What are the G forces leaving Earth orbit?
What is a Samsaran Word™?
What is the opposite of "eschatology"?
How can saying a song's name be a copyright violation?
How to install cross-compiler on Ubuntu 18.04?
Admob 2018 package for Unity (3.15.1) not showing ads in android mobile devices (banner, interstitial, rewarded video etc.)
C# method failing to function for no known reasonUnity3d Admob Reward Based Video errorAdmob unity rewarded videos not workingHow to show admob interstitial and reward ads in Unity game?Reward video not showing, and not giving reward. Unity 3dIntegrate admob Rewarded video in unityAdmob shows banner ad, but doesn't show video (Rewarded ads)how to store into a session and display current users informationUnity Admob Interstitial Ads Not ShowingAdMob/Unity - Rewarded Video are not showing
I have a game completed in unity and I have implemented Admob to my game. But ads are not running. Only, if I open the game and wait without playing, sometimes banner comes top of the screen. I could not find the problem. I switched my Unity from 2018.3.6 to newest version and tried to lower the version to 2017.1.1 but nothing changed. When I export the game and load it into my mobile phone nothing changes. I updated my sdk, jdk etc. I updated admob package to 3.15.1 nothing changed. What could be possibly wrong?
My system has programs like;
Unity 2018.3.6f1
SDK updated
JDK updated
Admob package 3.15.1
I used google admobs sample code which used to work in the past but for 2 days my brain is about to explode.
When I could not implement admob, I tried to use Unity Ads but this time only video's played and again not working banner or rewarded videos.
Is there anyone who is trying to publish a game with admob and have a problem as mine? Can you help me please?
I am also opened for the ideas of better ways to moneterize money other than admob. Which platform do you offer me to use?
Everything was perfect before, what has changed? I can not figure out with new admob package and jdk.
Also I edited my admob cs code like this:
using System;
using UnityEngine;
using GoogleMobileAds.Api;
using System.Collections;
public class AdmobManager : MonoBehaviour
public static AdmobManager Instance;
private BannerView bannerView;
private InterstitialAd interstitial;
private RewardBasedVideoAd rewardBasedVideo;
void Awake()
if (Instance != null)
Destroy(gameObject);
else
Instance = this;
DontDestroyOnLoad(gameObject);
void Start()
MobileAds.Initialize("ca-app-pub-***********************"); // admob game id
RequestBanner();
RequestInterstitial();
RequestShowRewardBasedVideo();
ShowBanner();
private void RequestBanner()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
if (this.bannerView != null)
this.bannerView.Destroy();
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
// Register for ad events.
RegisterDelegateForBanner();
// Load a banner ad.
bannerView.LoadAd(createAdRequest());
private void RequestInterstitial()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up interstitial ad before creating a new one.
if (this.interstitial != null)
this.interstitial.Destroy();
// Create an interstitial.
interstitial = new InterstitialAd(adUnitId);
// Register for ad events.
RegisterDelegateForInterstitial();
// Load an interstitial ad.
interstitial.LoadAd(createAdRequest());
void RequestShowRewardBasedVideo()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
rewardBasedVideo = RewardBasedVideoAd.Instance;
RegisterDelegateForShowRewardedVideo();
rewardBasedVideo.LoadAd(createAdRequest(), adUnitId);
// Returns an ad request with custom ad targeting.
private AdRequest createAdRequest()
return new AdRequest.Builder()
//.AddTestDevice(AdRequest.TestDeviceSimulator)
//.AddTestDevice("")
//.AddKeyword("")
//.SetGender(Gender.Male)
//.SetBirthday(new DateTime(1985, 1, 1))
//.TagForChildDirectedTreatment(false)
//.AddExtra("color_bg", "9B30FF")
.Build();
IEnumerator ShowBannerWhenReady()
while (bannerView == null)
yield return null;
bannerView.Show();
public void ShowBanner()
if (bannerView == null)
RequestBanner();
StartCoroutine(ShowBannerWhenReady());
if (bannerView != null)
StartCoroutine(ShowBannerWhenReady());
IEnumerator ShowInterstitialWhenReady()
while (!interstitial.IsLoaded())
yield return null;
interstitial.Show();
public void ShowInterstitial()
if (!interstitial.IsLoaded())
RequestInterstitial();
StartCoroutine(ShowInterstitialWhenReady());
if (interstitial.IsLoaded())
StartCoroutine(ShowInterstitialWhenReady());
IEnumerator ShowRewardedVideoWhenReady()
while (!rewardBasedVideo.IsLoaded())
yield return null;
rewardBasedVideo.Show();
public void ShowRewardBasedVideo()
if (!rewardBasedVideo.IsLoaded())
RequestShowRewardBasedVideo();
StartCoroutine(ShowRewardedVideoWhenReady());
if (rewardBasedVideo.IsLoaded())
StartCoroutine(ShowRewardedVideoWhenReady());
//-----------------------------------------------------------------------------
void RegisterDelegateForBanner()
bannerView.OnAdLoaded += HandleAdLoaded;
bannerView.OnAdFailedToLoad += HandleAdFailedToLoad;
bannerView.OnAdLoaded += HandleAdOpened;
bannerView.OnAdClosed += HandleAdClosed;
bannerView.OnAdLeavingApplication += HandleAdLeftApplication;
void UnRegisterDelegateForBanner()
bannerView.OnAdLoaded -= HandleAdLoaded;
bannerView.OnAdFailedToLoad -= HandleAdFailedToLoad;
bannerView.OnAdLoaded -= HandleAdOpened;
bannerView.OnAdClosed -= HandleAdClosed;
bannerView.OnAdLeavingApplication -= HandleAdLeftApplication;
void RegisterDelegateForInterstitial()
interstitial.OnAdLoaded += HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
interstitial.OnAdOpening += HandleInterstitialOpened;
interstitial.OnAdClosed += HandleInterstitialClosed;
interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;
void UnRegisterDelegateForInterstitial()
interstitial.OnAdLoaded -= HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad -= HandleInterstitialFailedToLoad;
interstitial.OnAdOpening -= HandleInterstitialOpened;
interstitial.OnAdClosed -= HandleInterstitialClosed;
interstitial.OnAdLeavingApplication -= HandleInterstitialLeftApplication;
void RegisterDelegateForShowRewardedVideo()
// RewardBasedVideoAd is a singleton, so handlers should only be registered once.
this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening += this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted += this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed += this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication;
void UnRegisterDelegateForShowRewardedVideo()
// RewardBasedVideoAd is a singleton, so handlers should only be registered once.
this.rewardBasedVideo.OnAdLoaded -= this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad -= this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening -= this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted -= this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded -= this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed -= this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication -= this.HandleRewardBasedVideoLeftApplication;
//--------------------------------------------------------------------------
public void HandleAdLoaded(object sender, EventArgs args)
ShowBanner();
public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
UnRegisterDelegateForBanner();
RequestBanner();
public void HandleAdOpened(object sender, EventArgs args)
void HandleAdClosing(object sender, EventArgs args)
public void HandleAdClosed(object sender, EventArgs args)
UnRegisterDelegateForBanner();
RequestBanner();
public void HandleAdLeftApplication(object sender, EventArgs args)
//------------------------------------------------------------
public void HandleInterstitialLoaded(object sender, EventArgs args)
public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
UnRegisterDelegateForInterstitial();
RequestInterstitial();
public void HandleInterstitialOpened(object sender, EventArgs args)
void HandleInterstitialClosing(object sender, EventArgs args)
public void HandleInterstitialClosed(object sender, EventArgs args)
UnRegisterDelegateForInterstitial();
RequestInterstitial();
public void HandleInterstitialLeftApplication(object sender, EventArgs args)
// ------------------------------------------------------------------
private void HandleRewardBasedVideoLeftApplication(object sender, EventArgs e)
private void HandleRewardBasedVideoClosed(object sender, EventArgs e)
UnRegisterDelegateForShowRewardedVideo();
RequestShowRewardBasedVideo();
private void HandleRewardBasedVideoRewarded(object sender, Reward e)
//string type = e.Type;
//double amount = e.Amount;
////Reawrd User here
//print("User rewarded with: " + amount.ToString() + " " + type);
//Debug.Log("Manually Control with DEBUG!!!");
private void HandleRewardBasedVideoStarted(object sender, EventArgs e)
private void HandleRewardBasedVideoOpened(object sender, EventArgs e)
private void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs e)
UnRegisterDelegateForShowRewardedVideo();
RequestShowRewardBasedVideo();
private void HandleRewardBasedVideoLoaded(object sender, EventArgs e)
c# unity3d admob
add a comment |
I have a game completed in unity and I have implemented Admob to my game. But ads are not running. Only, if I open the game and wait without playing, sometimes banner comes top of the screen. I could not find the problem. I switched my Unity from 2018.3.6 to newest version and tried to lower the version to 2017.1.1 but nothing changed. When I export the game and load it into my mobile phone nothing changes. I updated my sdk, jdk etc. I updated admob package to 3.15.1 nothing changed. What could be possibly wrong?
My system has programs like;
Unity 2018.3.6f1
SDK updated
JDK updated
Admob package 3.15.1
I used google admobs sample code which used to work in the past but for 2 days my brain is about to explode.
When I could not implement admob, I tried to use Unity Ads but this time only video's played and again not working banner or rewarded videos.
Is there anyone who is trying to publish a game with admob and have a problem as mine? Can you help me please?
I am also opened for the ideas of better ways to moneterize money other than admob. Which platform do you offer me to use?
Everything was perfect before, what has changed? I can not figure out with new admob package and jdk.
Also I edited my admob cs code like this:
using System;
using UnityEngine;
using GoogleMobileAds.Api;
using System.Collections;
public class AdmobManager : MonoBehaviour
public static AdmobManager Instance;
private BannerView bannerView;
private InterstitialAd interstitial;
private RewardBasedVideoAd rewardBasedVideo;
void Awake()
if (Instance != null)
Destroy(gameObject);
else
Instance = this;
DontDestroyOnLoad(gameObject);
void Start()
MobileAds.Initialize("ca-app-pub-***********************"); // admob game id
RequestBanner();
RequestInterstitial();
RequestShowRewardBasedVideo();
ShowBanner();
private void RequestBanner()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
if (this.bannerView != null)
this.bannerView.Destroy();
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
// Register for ad events.
RegisterDelegateForBanner();
// Load a banner ad.
bannerView.LoadAd(createAdRequest());
private void RequestInterstitial()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up interstitial ad before creating a new one.
if (this.interstitial != null)
this.interstitial.Destroy();
// Create an interstitial.
interstitial = new InterstitialAd(adUnitId);
// Register for ad events.
RegisterDelegateForInterstitial();
// Load an interstitial ad.
interstitial.LoadAd(createAdRequest());
void RequestShowRewardBasedVideo()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
rewardBasedVideo = RewardBasedVideoAd.Instance;
RegisterDelegateForShowRewardedVideo();
rewardBasedVideo.LoadAd(createAdRequest(), adUnitId);
// Returns an ad request with custom ad targeting.
private AdRequest createAdRequest()
return new AdRequest.Builder()
//.AddTestDevice(AdRequest.TestDeviceSimulator)
//.AddTestDevice("")
//.AddKeyword("")
//.SetGender(Gender.Male)
//.SetBirthday(new DateTime(1985, 1, 1))
//.TagForChildDirectedTreatment(false)
//.AddExtra("color_bg", "9B30FF")
.Build();
IEnumerator ShowBannerWhenReady()
while (bannerView == null)
yield return null;
bannerView.Show();
public void ShowBanner()
if (bannerView == null)
RequestBanner();
StartCoroutine(ShowBannerWhenReady());
if (bannerView != null)
StartCoroutine(ShowBannerWhenReady());
IEnumerator ShowInterstitialWhenReady()
while (!interstitial.IsLoaded())
yield return null;
interstitial.Show();
public void ShowInterstitial()
if (!interstitial.IsLoaded())
RequestInterstitial();
StartCoroutine(ShowInterstitialWhenReady());
if (interstitial.IsLoaded())
StartCoroutine(ShowInterstitialWhenReady());
IEnumerator ShowRewardedVideoWhenReady()
while (!rewardBasedVideo.IsLoaded())
yield return null;
rewardBasedVideo.Show();
public void ShowRewardBasedVideo()
if (!rewardBasedVideo.IsLoaded())
RequestShowRewardBasedVideo();
StartCoroutine(ShowRewardedVideoWhenReady());
if (rewardBasedVideo.IsLoaded())
StartCoroutine(ShowRewardedVideoWhenReady());
//-----------------------------------------------------------------------------
void RegisterDelegateForBanner()
bannerView.OnAdLoaded += HandleAdLoaded;
bannerView.OnAdFailedToLoad += HandleAdFailedToLoad;
bannerView.OnAdLoaded += HandleAdOpened;
bannerView.OnAdClosed += HandleAdClosed;
bannerView.OnAdLeavingApplication += HandleAdLeftApplication;
void UnRegisterDelegateForBanner()
bannerView.OnAdLoaded -= HandleAdLoaded;
bannerView.OnAdFailedToLoad -= HandleAdFailedToLoad;
bannerView.OnAdLoaded -= HandleAdOpened;
bannerView.OnAdClosed -= HandleAdClosed;
bannerView.OnAdLeavingApplication -= HandleAdLeftApplication;
void RegisterDelegateForInterstitial()
interstitial.OnAdLoaded += HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
interstitial.OnAdOpening += HandleInterstitialOpened;
interstitial.OnAdClosed += HandleInterstitialClosed;
interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;
void UnRegisterDelegateForInterstitial()
interstitial.OnAdLoaded -= HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad -= HandleInterstitialFailedToLoad;
interstitial.OnAdOpening -= HandleInterstitialOpened;
interstitial.OnAdClosed -= HandleInterstitialClosed;
interstitial.OnAdLeavingApplication -= HandleInterstitialLeftApplication;
void RegisterDelegateForShowRewardedVideo()
// RewardBasedVideoAd is a singleton, so handlers should only be registered once.
this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening += this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted += this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed += this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication;
void UnRegisterDelegateForShowRewardedVideo()
// RewardBasedVideoAd is a singleton, so handlers should only be registered once.
this.rewardBasedVideo.OnAdLoaded -= this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad -= this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening -= this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted -= this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded -= this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed -= this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication -= this.HandleRewardBasedVideoLeftApplication;
//--------------------------------------------------------------------------
public void HandleAdLoaded(object sender, EventArgs args)
ShowBanner();
public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
UnRegisterDelegateForBanner();
RequestBanner();
public void HandleAdOpened(object sender, EventArgs args)
void HandleAdClosing(object sender, EventArgs args)
public void HandleAdClosed(object sender, EventArgs args)
UnRegisterDelegateForBanner();
RequestBanner();
public void HandleAdLeftApplication(object sender, EventArgs args)
//------------------------------------------------------------
public void HandleInterstitialLoaded(object sender, EventArgs args)
public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
UnRegisterDelegateForInterstitial();
RequestInterstitial();
public void HandleInterstitialOpened(object sender, EventArgs args)
void HandleInterstitialClosing(object sender, EventArgs args)
public void HandleInterstitialClosed(object sender, EventArgs args)
UnRegisterDelegateForInterstitial();
RequestInterstitial();
public void HandleInterstitialLeftApplication(object sender, EventArgs args)
// ------------------------------------------------------------------
private void HandleRewardBasedVideoLeftApplication(object sender, EventArgs e)
private void HandleRewardBasedVideoClosed(object sender, EventArgs e)
UnRegisterDelegateForShowRewardedVideo();
RequestShowRewardBasedVideo();
private void HandleRewardBasedVideoRewarded(object sender, Reward e)
//string type = e.Type;
//double amount = e.Amount;
////Reawrd User here
//print("User rewarded with: " + amount.ToString() + " " + type);
//Debug.Log("Manually Control with DEBUG!!!");
private void HandleRewardBasedVideoStarted(object sender, EventArgs e)
private void HandleRewardBasedVideoOpened(object sender, EventArgs e)
private void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs e)
UnRegisterDelegateForShowRewardedVideo();
RequestShowRewardBasedVideo();
private void HandleRewardBasedVideoLoaded(object sender, EventArgs e)
c# unity3d admob
add a comment |
I have a game completed in unity and I have implemented Admob to my game. But ads are not running. Only, if I open the game and wait without playing, sometimes banner comes top of the screen. I could not find the problem. I switched my Unity from 2018.3.6 to newest version and tried to lower the version to 2017.1.1 but nothing changed. When I export the game and load it into my mobile phone nothing changes. I updated my sdk, jdk etc. I updated admob package to 3.15.1 nothing changed. What could be possibly wrong?
My system has programs like;
Unity 2018.3.6f1
SDK updated
JDK updated
Admob package 3.15.1
I used google admobs sample code which used to work in the past but for 2 days my brain is about to explode.
When I could not implement admob, I tried to use Unity Ads but this time only video's played and again not working banner or rewarded videos.
Is there anyone who is trying to publish a game with admob and have a problem as mine? Can you help me please?
I am also opened for the ideas of better ways to moneterize money other than admob. Which platform do you offer me to use?
Everything was perfect before, what has changed? I can not figure out with new admob package and jdk.
Also I edited my admob cs code like this:
using System;
using UnityEngine;
using GoogleMobileAds.Api;
using System.Collections;
public class AdmobManager : MonoBehaviour
public static AdmobManager Instance;
private BannerView bannerView;
private InterstitialAd interstitial;
private RewardBasedVideoAd rewardBasedVideo;
void Awake()
if (Instance != null)
Destroy(gameObject);
else
Instance = this;
DontDestroyOnLoad(gameObject);
void Start()
MobileAds.Initialize("ca-app-pub-***********************"); // admob game id
RequestBanner();
RequestInterstitial();
RequestShowRewardBasedVideo();
ShowBanner();
private void RequestBanner()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
if (this.bannerView != null)
this.bannerView.Destroy();
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
// Register for ad events.
RegisterDelegateForBanner();
// Load a banner ad.
bannerView.LoadAd(createAdRequest());
private void RequestInterstitial()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up interstitial ad before creating a new one.
if (this.interstitial != null)
this.interstitial.Destroy();
// Create an interstitial.
interstitial = new InterstitialAd(adUnitId);
// Register for ad events.
RegisterDelegateForInterstitial();
// Load an interstitial ad.
interstitial.LoadAd(createAdRequest());
void RequestShowRewardBasedVideo()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
rewardBasedVideo = RewardBasedVideoAd.Instance;
RegisterDelegateForShowRewardedVideo();
rewardBasedVideo.LoadAd(createAdRequest(), adUnitId);
// Returns an ad request with custom ad targeting.
private AdRequest createAdRequest()
return new AdRequest.Builder()
//.AddTestDevice(AdRequest.TestDeviceSimulator)
//.AddTestDevice("")
//.AddKeyword("")
//.SetGender(Gender.Male)
//.SetBirthday(new DateTime(1985, 1, 1))
//.TagForChildDirectedTreatment(false)
//.AddExtra("color_bg", "9B30FF")
.Build();
IEnumerator ShowBannerWhenReady()
while (bannerView == null)
yield return null;
bannerView.Show();
public void ShowBanner()
if (bannerView == null)
RequestBanner();
StartCoroutine(ShowBannerWhenReady());
if (bannerView != null)
StartCoroutine(ShowBannerWhenReady());
IEnumerator ShowInterstitialWhenReady()
while (!interstitial.IsLoaded())
yield return null;
interstitial.Show();
public void ShowInterstitial()
if (!interstitial.IsLoaded())
RequestInterstitial();
StartCoroutine(ShowInterstitialWhenReady());
if (interstitial.IsLoaded())
StartCoroutine(ShowInterstitialWhenReady());
IEnumerator ShowRewardedVideoWhenReady()
while (!rewardBasedVideo.IsLoaded())
yield return null;
rewardBasedVideo.Show();
public void ShowRewardBasedVideo()
if (!rewardBasedVideo.IsLoaded())
RequestShowRewardBasedVideo();
StartCoroutine(ShowRewardedVideoWhenReady());
if (rewardBasedVideo.IsLoaded())
StartCoroutine(ShowRewardedVideoWhenReady());
//-----------------------------------------------------------------------------
void RegisterDelegateForBanner()
bannerView.OnAdLoaded += HandleAdLoaded;
bannerView.OnAdFailedToLoad += HandleAdFailedToLoad;
bannerView.OnAdLoaded += HandleAdOpened;
bannerView.OnAdClosed += HandleAdClosed;
bannerView.OnAdLeavingApplication += HandleAdLeftApplication;
void UnRegisterDelegateForBanner()
bannerView.OnAdLoaded -= HandleAdLoaded;
bannerView.OnAdFailedToLoad -= HandleAdFailedToLoad;
bannerView.OnAdLoaded -= HandleAdOpened;
bannerView.OnAdClosed -= HandleAdClosed;
bannerView.OnAdLeavingApplication -= HandleAdLeftApplication;
void RegisterDelegateForInterstitial()
interstitial.OnAdLoaded += HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
interstitial.OnAdOpening += HandleInterstitialOpened;
interstitial.OnAdClosed += HandleInterstitialClosed;
interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;
void UnRegisterDelegateForInterstitial()
interstitial.OnAdLoaded -= HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad -= HandleInterstitialFailedToLoad;
interstitial.OnAdOpening -= HandleInterstitialOpened;
interstitial.OnAdClosed -= HandleInterstitialClosed;
interstitial.OnAdLeavingApplication -= HandleInterstitialLeftApplication;
void RegisterDelegateForShowRewardedVideo()
// RewardBasedVideoAd is a singleton, so handlers should only be registered once.
this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening += this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted += this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed += this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication;
void UnRegisterDelegateForShowRewardedVideo()
// RewardBasedVideoAd is a singleton, so handlers should only be registered once.
this.rewardBasedVideo.OnAdLoaded -= this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad -= this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening -= this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted -= this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded -= this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed -= this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication -= this.HandleRewardBasedVideoLeftApplication;
//--------------------------------------------------------------------------
public void HandleAdLoaded(object sender, EventArgs args)
ShowBanner();
public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
UnRegisterDelegateForBanner();
RequestBanner();
public void HandleAdOpened(object sender, EventArgs args)
void HandleAdClosing(object sender, EventArgs args)
public void HandleAdClosed(object sender, EventArgs args)
UnRegisterDelegateForBanner();
RequestBanner();
public void HandleAdLeftApplication(object sender, EventArgs args)
//------------------------------------------------------------
public void HandleInterstitialLoaded(object sender, EventArgs args)
public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
UnRegisterDelegateForInterstitial();
RequestInterstitial();
public void HandleInterstitialOpened(object sender, EventArgs args)
void HandleInterstitialClosing(object sender, EventArgs args)
public void HandleInterstitialClosed(object sender, EventArgs args)
UnRegisterDelegateForInterstitial();
RequestInterstitial();
public void HandleInterstitialLeftApplication(object sender, EventArgs args)
// ------------------------------------------------------------------
private void HandleRewardBasedVideoLeftApplication(object sender, EventArgs e)
private void HandleRewardBasedVideoClosed(object sender, EventArgs e)
UnRegisterDelegateForShowRewardedVideo();
RequestShowRewardBasedVideo();
private void HandleRewardBasedVideoRewarded(object sender, Reward e)
//string type = e.Type;
//double amount = e.Amount;
////Reawrd User here
//print("User rewarded with: " + amount.ToString() + " " + type);
//Debug.Log("Manually Control with DEBUG!!!");
private void HandleRewardBasedVideoStarted(object sender, EventArgs e)
private void HandleRewardBasedVideoOpened(object sender, EventArgs e)
private void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs e)
UnRegisterDelegateForShowRewardedVideo();
RequestShowRewardBasedVideo();
private void HandleRewardBasedVideoLoaded(object sender, EventArgs e)
c# unity3d admob
I have a game completed in unity and I have implemented Admob to my game. But ads are not running. Only, if I open the game and wait without playing, sometimes banner comes top of the screen. I could not find the problem. I switched my Unity from 2018.3.6 to newest version and tried to lower the version to 2017.1.1 but nothing changed. When I export the game and load it into my mobile phone nothing changes. I updated my sdk, jdk etc. I updated admob package to 3.15.1 nothing changed. What could be possibly wrong?
My system has programs like;
Unity 2018.3.6f1
SDK updated
JDK updated
Admob package 3.15.1
I used google admobs sample code which used to work in the past but for 2 days my brain is about to explode.
When I could not implement admob, I tried to use Unity Ads but this time only video's played and again not working banner or rewarded videos.
Is there anyone who is trying to publish a game with admob and have a problem as mine? Can you help me please?
I am also opened for the ideas of better ways to moneterize money other than admob. Which platform do you offer me to use?
Everything was perfect before, what has changed? I can not figure out with new admob package and jdk.
Also I edited my admob cs code like this:
using System;
using UnityEngine;
using GoogleMobileAds.Api;
using System.Collections;
public class AdmobManager : MonoBehaviour
public static AdmobManager Instance;
private BannerView bannerView;
private InterstitialAd interstitial;
private RewardBasedVideoAd rewardBasedVideo;
void Awake()
if (Instance != null)
Destroy(gameObject);
else
Instance = this;
DontDestroyOnLoad(gameObject);
void Start()
MobileAds.Initialize("ca-app-pub-***********************"); // admob game id
RequestBanner();
RequestInterstitial();
RequestShowRewardBasedVideo();
ShowBanner();
private void RequestBanner()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
if (this.bannerView != null)
this.bannerView.Destroy();
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
// Register for ad events.
RegisterDelegateForBanner();
// Load a banner ad.
bannerView.LoadAd(createAdRequest());
private void RequestInterstitial()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up interstitial ad before creating a new one.
if (this.interstitial != null)
this.interstitial.Destroy();
// Create an interstitial.
interstitial = new InterstitialAd(adUnitId);
// Register for ad events.
RegisterDelegateForInterstitial();
// Load an interstitial ad.
interstitial.LoadAd(createAdRequest());
void RequestShowRewardBasedVideo()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*************************";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
rewardBasedVideo = RewardBasedVideoAd.Instance;
RegisterDelegateForShowRewardedVideo();
rewardBasedVideo.LoadAd(createAdRequest(), adUnitId);
// Returns an ad request with custom ad targeting.
private AdRequest createAdRequest()
return new AdRequest.Builder()
//.AddTestDevice(AdRequest.TestDeviceSimulator)
//.AddTestDevice("")
//.AddKeyword("")
//.SetGender(Gender.Male)
//.SetBirthday(new DateTime(1985, 1, 1))
//.TagForChildDirectedTreatment(false)
//.AddExtra("color_bg", "9B30FF")
.Build();
IEnumerator ShowBannerWhenReady()
while (bannerView == null)
yield return null;
bannerView.Show();
public void ShowBanner()
if (bannerView == null)
RequestBanner();
StartCoroutine(ShowBannerWhenReady());
if (bannerView != null)
StartCoroutine(ShowBannerWhenReady());
IEnumerator ShowInterstitialWhenReady()
while (!interstitial.IsLoaded())
yield return null;
interstitial.Show();
public void ShowInterstitial()
if (!interstitial.IsLoaded())
RequestInterstitial();
StartCoroutine(ShowInterstitialWhenReady());
if (interstitial.IsLoaded())
StartCoroutine(ShowInterstitialWhenReady());
IEnumerator ShowRewardedVideoWhenReady()
while (!rewardBasedVideo.IsLoaded())
yield return null;
rewardBasedVideo.Show();
public void ShowRewardBasedVideo()
if (!rewardBasedVideo.IsLoaded())
RequestShowRewardBasedVideo();
StartCoroutine(ShowRewardedVideoWhenReady());
if (rewardBasedVideo.IsLoaded())
StartCoroutine(ShowRewardedVideoWhenReady());
//-----------------------------------------------------------------------------
void RegisterDelegateForBanner()
bannerView.OnAdLoaded += HandleAdLoaded;
bannerView.OnAdFailedToLoad += HandleAdFailedToLoad;
bannerView.OnAdLoaded += HandleAdOpened;
bannerView.OnAdClosed += HandleAdClosed;
bannerView.OnAdLeavingApplication += HandleAdLeftApplication;
void UnRegisterDelegateForBanner()
bannerView.OnAdLoaded -= HandleAdLoaded;
bannerView.OnAdFailedToLoad -= HandleAdFailedToLoad;
bannerView.OnAdLoaded -= HandleAdOpened;
bannerView.OnAdClosed -= HandleAdClosed;
bannerView.OnAdLeavingApplication -= HandleAdLeftApplication;
void RegisterDelegateForInterstitial()
interstitial.OnAdLoaded += HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
interstitial.OnAdOpening += HandleInterstitialOpened;
interstitial.OnAdClosed += HandleInterstitialClosed;
interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;
void UnRegisterDelegateForInterstitial()
interstitial.OnAdLoaded -= HandleInterstitialLoaded;
interstitial.OnAdFailedToLoad -= HandleInterstitialFailedToLoad;
interstitial.OnAdOpening -= HandleInterstitialOpened;
interstitial.OnAdClosed -= HandleInterstitialClosed;
interstitial.OnAdLeavingApplication -= HandleInterstitialLeftApplication;
void RegisterDelegateForShowRewardedVideo()
// RewardBasedVideoAd is a singleton, so handlers should only be registered once.
this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening += this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted += this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed += this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication;
void UnRegisterDelegateForShowRewardedVideo()
// RewardBasedVideoAd is a singleton, so handlers should only be registered once.
this.rewardBasedVideo.OnAdLoaded -= this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad -= this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening -= this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted -= this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded -= this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed -= this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication -= this.HandleRewardBasedVideoLeftApplication;
//--------------------------------------------------------------------------
public void HandleAdLoaded(object sender, EventArgs args)
ShowBanner();
public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
UnRegisterDelegateForBanner();
RequestBanner();
public void HandleAdOpened(object sender, EventArgs args)
void HandleAdClosing(object sender, EventArgs args)
public void HandleAdClosed(object sender, EventArgs args)
UnRegisterDelegateForBanner();
RequestBanner();
public void HandleAdLeftApplication(object sender, EventArgs args)
//------------------------------------------------------------
public void HandleInterstitialLoaded(object sender, EventArgs args)
public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
UnRegisterDelegateForInterstitial();
RequestInterstitial();
public void HandleInterstitialOpened(object sender, EventArgs args)
void HandleInterstitialClosing(object sender, EventArgs args)
public void HandleInterstitialClosed(object sender, EventArgs args)
UnRegisterDelegateForInterstitial();
RequestInterstitial();
public void HandleInterstitialLeftApplication(object sender, EventArgs args)
// ------------------------------------------------------------------
private void HandleRewardBasedVideoLeftApplication(object sender, EventArgs e)
private void HandleRewardBasedVideoClosed(object sender, EventArgs e)
UnRegisterDelegateForShowRewardedVideo();
RequestShowRewardBasedVideo();
private void HandleRewardBasedVideoRewarded(object sender, Reward e)
//string type = e.Type;
//double amount = e.Amount;
////Reawrd User here
//print("User rewarded with: " + amount.ToString() + " " + type);
//Debug.Log("Manually Control with DEBUG!!!");
private void HandleRewardBasedVideoStarted(object sender, EventArgs e)
private void HandleRewardBasedVideoOpened(object sender, EventArgs e)
private void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs e)
UnRegisterDelegateForShowRewardedVideo();
RequestShowRewardBasedVideo();
private void HandleRewardBasedVideoLoaded(object sender, EventArgs e)
c# unity3d admob
c# unity3d admob
edited Mar 17 at 17:53
silkworm
asked Mar 2 at 1:55
silkwormsilkworm
184
184
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54954521%2fadmob-2018-package-for-unity-3-15-1-not-showing-ads-in-android-mobile-devices%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54954521%2fadmob-2018-package-for-unity-3-15-1-not-showing-ads-in-android-mobile-devices%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown