Admob setup
Hi guys! I'm new to programming and I'm suffering cause I can't set up AdMob but I followed every step and I don't know what's wrong with this. I have a script but in the game it doesn't show any ads. (Maybe the problem is that I didn't set up the app-ads.txt file but I don't have a website and I think its not a reason to not show ads). I hope somebody can help me. Thanks! Here is the script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
using UnityEngine.UI; using System; using GoogleMobileAds.Api;
public class AdMobScript : MonoBehaviour {
string App_ID = "ca-app-pub-1698739946462575~8377893712";
string Interstitial_AD_ID = "ca-app-pub-1698739946462575/2294032790";
private InterstitialAd interstitial;
// Start is called before the first frame update
void Start()
{
MobileAds.Initialize(App_ID);
}
public void RequestInterstitial()
{
// Initialize an InterstitialAd.
this.interstitial = new InterstitialAd(Interstitial_AD_ID);
// Called when an ad request has successfully loaded.
this.interstitial.OnAdLoaded += HandleOnAdLoaded;
// Called when an ad request failed to load.
this.interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad;
// Called when an ad is shown.
this.interstitial.OnAdOpening += HandleOnAdOpened;
// Called when the ad is closed.
this.interstitial.OnAdClosed += HandleOnAdClosed;
// Called when the ad click caused the user to leave the application.
this.interstitial.OnAdLeavingApplication += HandleOnAdLeavingApplication;
AdRequest request = new AdRequest.Builder().Build();
this.interstitial.LoadAd(request);
}
public void ShowInterstitialAd()
{
if (this.interstitial.IsLoaded())
{
this.interstitial.Show();
}
}
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);
}
public void HandleOnAdOpened(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdOpened event received");
}
public void HandleOnAdClosed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdClosed event received");
}
public void HandleOnAdLeavingApplication(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLeavingApplication event received");
}
}
Your answer
Follow this Question
Related Questions
Admob Interstiate doesn't show 0 Answers
Admob Errors 1 Answer
Interstitial Ads Network 0 Answers
Admob not working i not find a solution 1 Answer
I can not build my project after I imported Ironsource SDK. 2019.4.5f1 0 Answers