我想将Google admob添加到我的统一游戏中。 https://github.com/googleads/googleads-mobile-unity/releases 但是横幅没有出现
根据https://developers.google.com/admob/unity/start 我编写了简单的脚本,并从Google Admob控制台(https://apps.admob.com)获取标语和应用程序的ID。
public class ADS : MonoBehaviour
{
string ads_banner_id = "ca-app-pub-6807450626654540/6028463012";
string appID = "ca-app-pub-6807450626654540~4860573772";
BannerView bannerView;
public void InitBanner()
{
Debug.Log("InitBanner");
bannerView = new BannerView(ads_banner_id, AdSize.Banner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder().Build();
bannerView.OnAdLoaded += (sender, args) =>
{
Debug.Log("InitBanner OnAdLoaded : " + sender + "->" + sender.GetType() + "\nargs[" + args + "]");
bannerView.Show();
};
bannerView.OnAdFailedToLoad += (sender, args) =>
{
Debug.Log("InitBanner OnAdFailedToLoad :" + args.Message);
};
bannerView.LoadAd(request);
}
void Start()
{
MobileAds.Initialize(appID);
}
}
统一Admob设置
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.unity.ads" android:versionName="1.0" android:versionCode="1">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
<application>
<uses-library android:required="false" android:name="org.apache.http.legacy" />
<!-- 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-6807450626654540~4860573772" />
<meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true" />
</application>
</manifest>
和登录: