Mine работает по следующим шагам:
Шаг 1 - Установка JAVA_HOME в windows:
https://javatutorial.net/set-java-home-windows-10
Шаг 2 - Переключите ваш проект на Android
Шаг 3 - Добавьте приложение AdMob в свой проект
Assets> Google Mobile Ads> Настройки>
(затем включите google admob и введите appid, который вы видите в окне инспектора)
Шаг 4 - Затем принудительное разрешение проекта Assets> Play Services Resolver> Android Resolver> Force Resolve
Шаг 5 - сценарий
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using System;
public class AdScript : MonoBehaviour
{
string AppId = "(your App ID)";
string InterstitialAdID = "(test adid or real adid)";
string BannerAdId = "(test adid or real adid)";
private InterstitialAd interstitial;
private BannerView bannerView;
void Start()
{
MobileAds.Initialize(AppId);
if (Application.platform == RuntimePlatform.Android)
{
RequestBannerAd();
RequestInterstitial();
}
}
private void RequestInterstitial()
{
// Initialize an InterstitialAd.
this.interstitial = new InterstitialAd(InterstitialAdID);
// 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;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
this.interstitial.LoadAd(request);
}
private void RequestBannerAd()
{
this.bannerView = new BannerView(BannerAdId, AdSize.Banner, AdPosition.Top);
// Create an empty ad request.
// Called when an ad request has successfully loaded.
this.bannerView.OnAdLoaded += this.HandleOnAdLoaded;
// Called when an ad request failed to load.
this.bannerView.OnAdFailedToLoad += this.HandleOnAdFailedToLoad;
// Called when an ad is clicked.
this.bannerView.OnAdOpening += this.HandleOnAdOpened;
// Called when the user returned from the app after an ad click.
this.bannerView.OnAdClosed += this.HandleOnAdClosed;
// Called when the ad click caused the user to leave the application.
this.bannerView.OnAdLeavingApplication += this.HandleOnAdLeavingApplication;
}
public void ShowinterstitialAds()
{
if (this.interstitial.IsLoaded())
{
this.interstitial.Show();
}
}
public void ShowbannerViewAds()
{
AdRequest request = new AdRequest.Builder().Build();
Load the banner with the request.
this.bannerView.LoadAd(request);
}
#region interstitial and banned handler
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");
RequestInterstitial();
}
public void HandleOnAdLeavingApplication(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLeavingApplication event received");
}
#endregion
}
Надеюсь, это сработает;)