当我测试广告在iOS上正常运行时,我刚刚在Android和iOS上启动了名为Dodge:Game的应用。在两个平台上都启动游戏时,Android上没有广告,而Admob仪表板中没有任何请求。适用于iOS的情况。
这是我用来调用广告的代码:
using UnityEngine;
using UnityEngine.SceneManagement;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class Menu : MonoBehaviour {
private BannerView bannerView;
private void Awake()
{
SetupAds();
}
void SetupAds()
{
if (PlayerPrefs.HasKey("AdFree"))
return;
#if UNITY_IPHONE
string appId = "ca-app-pub-9468963556585973~6866139959";
#elif UNITY_ANDROID
string appId = "ca-app-pub-9468963556585973~5324184926";
#else
sting appId = "unexpected_platform";
#endif
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(appId);
this.RequestBanner();
}
private void RequestBanner()
{
#if UNITY_IPHONE
string adUnitId = "ca-app-pub-9468963556585973/6704565848";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-9468963556585973/7268247018";
#else
string adUnitId = "unexpected_platform";
#endif
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the banner with the request.
bannerView.LoadAd(request);
}
public void StartGame ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void DisableAds()
{
Debug.Log("Ads disabled");
if (PlayerPrefs.HasKey("AdFree"))
print("Ads already removed");
else{
PlayerPrefs.SetInt("AdFree", 1);
PlayerPrefs.Save();
bannerView.Destroy();
}
}
}
答案 0 :(得分:0)
只需重新导入Google AdMob sdk。就是这样。