У меня закончена игра в единстве, и я добавил Admob в свою игру.Но реклама не показывается.Только если я открываю игру и жду без игры, иногда баннер выходит на верх экрана.Я не мог найти проблему.Я переключил свой Unity с 2018.3.6 на последнюю версию и попытался снизить версию до 2017.1.1, но ничего не изменилось.Когда я экспортирую игру и загружаю ее в свой мобильный телефон, ничего не меняется.Я обновил свой SDK, JDK и т. Д. Я обновил пакет ADMOB до 3.15.1, ничего не изменилось.Что может быть не так?В моей системе есть такие программы, как:
Unity 2018.3.6f1
SDK обновлено
JDK обновлено
пакет Admob 3.15.1
Я использовал пример кода Google Admobs, который работал в прошлом, но в течение двух дней мой мозгвзрываться.
Когда я не мог внедрить admob, я пытался использовать Unity Ads, но на этот раз проигрывалось только видео, и опять не работал баннер или видео с вознаграждением.
Есть ли кто-нибудь, кто пытается опубликовать игрус admob и есть проблема как у меня?Можете ли вы помочь мне, пожалуйста?
Я также открыт для идей лучших способов монетизации денег, кроме admob.Какую платформу вы предлагаете мне использовать?
Раньше все было идеально, что изменилось?Я не могу разобраться с новым пакетом admob и jdk.
Также я отредактировал свой код admob cs так:
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)
{
}
}