my game is not showing admob real ads but it is working with test ads. I have created a script that shows ads on button pressed. when i checked my admob app reports I found that It got 663 ad request. Please help me.
here is my admob script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using System;
public class InterstitialAdmob : MonoBehaviour {
private InterstitialAd interstitial;
private bool _showads = false;
// Use this for initialization
void Update()
{
if (_showads) {
ShowAdsss();
}
}
public void RequestInterstitial()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-7127121626594253/9986792508";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
string adUnitId = "unexpected_platform";
#endif
// Initialize an InterstitialAd.
this.interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
this.interstitial.LoadAd(request);
// Called when an ad is shown.
// Called when an ad request has successfully loaded.
this.interstitial.OnAdLoaded += HandleOnAdLoaded;
// Called when an ad request failed to load.
this.interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad;
//hhhhhhhhhhhhhhhhhhhhh
this.interstitial.OnAdOpening += HandleOnAdOpened;
// Called when the ad is closed.
this.interstitial.OnAdClosed += HandleOnAdClosed;
_showads = true;
}
public void ShowAdsss()
{
if (this.interstitial.IsLoaded())
{
this.interstitial.Show();
}
}
public void HandleOnAdOpened(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdOpened event received");
}
public void HandleOnAdClosed(object sender, EventArgs args)
{
this.interstitial.Destroy();
MonoBehaviour.print("HandleAdClosed event received");
}
public void HandleOnAdLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLoaded event received");
}
public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
MonoBehaviour.print("HandleFailedToReceiveAd event received with message: "
+ args.Message);
}
}
here is the piece of code my button is accessing
...............
public InterstitialAdmob _ads;
...............
public void OnPlau() {
difficultyOptions.SetActive(true);
MenuParentObject.SetActive(false);
_ads.RequestInterstitial();
_ads.ShowAdsss();
}
↧