我在我的unity游戏项目android build中集成了广告mob横幅广告
但有时广告是在展示,但大多数时候不是
显示百分比将只有4%的100%
我不知道为什么会这样
我从developers.google获得了下面的代码,我可以显示广告,但它并没有在每一个初创公司都显示横幅应用程序坦率地说,它只在第一次或第二次创业后显示广告,而不再。
我试图找到解决方案,但看起来所有的解决方案都是一样的。
所以,我被困在这里
using System.Collections;
using System.Collections.Generic;
using GoogleMobileAds;
using GoogleMobileAds.Api;
using UnityEngine;
public class BannerAd : MonoBehaviour
{
private BannerView bannerView;
// Use this for initialization
void Start ()
{
string appID = "ca-app-pub-id"; // this is appId
MobileAds.Initialize (appID);
string adUnitId = "ca-app-pub-adUnitId"; // adUnitID
this.showBannerAd (adUnitId);
}
private void showBannerAd (string adUnitId)
{
//Create a custom ad size at the bottom of the screen
AdSize adSize = new AdSize (250, 50);
bannerView = new BannerView (adUnitId, adSize, AdPosition.Bottom);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder ().Build ();
// Load the banner with the request.
bannerView.LoadAd (request);
StartCoroutine(bannerAdTime());
}
IEnumerator bannerAdTime ()
{
yield return new WaitForSeconds (300f);
RequestNewAd();
}
private void RequestNewAd ()
{
// Create an empty ad request.
AdRequest request = new AdRequest.Builder ().Build ();
// Load the banner with the request.
bannerView.LoadAd (request);
StartCoroutine(bannerAdTime());
}
// Update is called once per frame
void Update ()
{
}
}
最佳答案
1.检查是否已将插件安装为文档https://github.com/unity-plugins/Unity-Admob
2.编辑androidmanifest.xml并配置admob app id
此配置是admob从17.0版开始请求的,如果不配置,应用程序将崩溃。请在应用程序中添加元数据标记并将值设置为admob appid
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="your admob app id"/>
示例代码
<application android:theme="@style/UnityThemeSelector"
android:icon="@drawable/app_icon"
android:label="@string/app_name" >
<activity
android:name="com.unity3d.player.UnityPlayerActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>
3.init admob unity插件
创建一个c脚本,将脚本拖动到场景中的对象,在脚本文件中添加以下代码
using admob;
Admob.Instance().initSDK("admob appid", new AdProperties());//admob id with format ca-app-pub-3940256099942544~3347511713
//Admob.Instance().initAdmob("ca-app-pub-3940256099942544/2934735716", new AdProperties());
4.在Unity应用程序中添加AdMob横幅
Admob.Instance().showBannerRelative("your admob banner unit id",AdSize.BANNER, AdPosition.BOTTOM_CENTER, 0);
关于c# - Admob横幅广告在Unity3D中无法正常运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51463674/