Admob のテスト広告は、テスト デバイスのいずれにも表示されませんが、Unity エディターに読み込まれていることが記録されます。
Android の依存関係を解決しました。マニフェストと AddCaller を表示します。Google リポジトリとプレイ サービス SDK があります。エラーは発生しませんが、テスト広告は表示されません。
Android マニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<!--
This Google Mobile Ads plugin library manifest will get merged with your
application's manifest, adding the necessary activity and permissions
required for displaying ads. android:minSdkVersion="14"
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.unity.ads"
android:versionName="1.0"
android:versionCode="1">
<!-- Required -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk android:targetSdkVersion="19" />
<application>
<!-- Your AdMob App ID will look similar to this sample ID:
ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxx~xxxxxxx"/>
</application>
</manifest>
アドスクリプト:
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
public class AddScript : MonoBehaviour
{
private string AppID = "ca-app-pub-xxxxxxxx~xxxxxxxx";
private BannerView bannerAD;
public InterstitialAd interAD;
public int addTick;
// Start is called before the first frame update
void Start()
{
string appId = AppID;
//Initialize Ads SDK
MobileAds.Initialize(appId);
RequestInterstitial();
RequestBanner();
}
private void OnLevelWasLoaded(int level)
{
if (level == 2)
{
ShowInterstitial();
}
if(level == 1)
{
bannerAD.Show();
}
}
private void RequestInterstitial()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
string adUnitId = "unexpected_platform";
#endif
// Initialize an InterstitialAd.
this.interAD = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().AddTestDevice("xxxxxxxxxxxx").Build();
// Called when an ad request has successfully loaded.
interAD.OnAdLoaded += HandleOnAdLoaded;
// Called when an ad request failed to load.
interAD.OnAdFailedToLoad += HandleOnAdFailedToLoad;
// Load the interstitial with the request.
this.interAD.LoadAd(request);
}
private void ShowInterstitial()
{
if (this.interAD.IsLoaded())
{
this.interAD.Show();
}
else
{
MonoBehaviour.print("Interstitial is not ready yet");
}
}
private void RequestBanner()
{
string adUnitId = "ca-app-pub-3940256099942544/6300978111";
// Create a 320x50 banner at the top of the screen.
bannerAD = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().AddTestDevice("xxxxxxxxxxx").Build();
// Load the banner with the request.
bannerAD.LoadAd(request);
}
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);
RequestInterstitial();
}
}
テスト バナーとテスト インタースティシャルが表示されるはずですが、何も起こりません。
コンソールにエラーや警告はなく、ダミーが正しく読み込まれて表示されたことが示されます。