Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Admob横幅广告在Unity3D中无法正常工作_C#_Android_Unity3d_Admob - Fatal编程技术网

C# Admob横幅广告在Unity3D中无法正常工作

C# Admob横幅广告在Unity3D中无法正常工作,c#,android,unity3d,admob,C#,Android,Unity3d,Admob,我将广告暴民横幅广告集成到我的Unity游戏项目android构建中 但有时广告会出现,但大多数时候不是 显示百分比仅为100%中的4% 我不知道为什么会这样 我从中获得以下代码,我可以显示广告,但它不会在每一家初创公司上显示横幅应用坦率地说,它只在构建后的第一家或第二家初创公司上显示广告,不再显示了 我试图找到解决方案,但看起来所有的解决方案都是一样的 所以,我被困在这里了 using System.Collections; using System.Collections.Generic;

我将广告暴民横幅广告集成到我的Unity游戏项目android构建中

但有时广告会出现,但大多数时候不是

显示百分比仅为100%中的4%

我不知道为什么会这样

我从中获得以下代码,我可以显示广告,但它不会在每一家初创公司上显示横幅应用坦率地说,它只在构建后的第一家或第二家初创公司上显示广告,不再显示了

我试图找到解决方案,但看起来所有的解决方案都是一样的

所以,我被困在这里了

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 ()
    {

    }
}
我找到了解决办法

问题出在我的模拟器上

使用真实设备工作正常

而且没有必要使用共同例行程序

以下代码足以显示BannderAds

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);

    }


}

1.检查您是否已将插件安装为文档

2.编辑AndroidManifest.xml并配置Admob应用程序ID admob从17.0版开始需要此配置,如果未配置,应用程序将崩溃。在应用程序中添加元数据标记,并将值设置为admob appid

<meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="your admob app id"/>
4.在Unity应用程序中添加Admob横幅

Admob.Instance().showBannerRelative("your admob banner unit id",AdSize.BANNER, AdPosition.BOTTOM_CENTER, 0);

您能否尝试使用测试广告,看看问题是否仍然存在?它可以告诉我们问题是在admob fill中,还是在你的代码中。好的,我会尝试一下并让你知道谢谢,伙计,它工作正常,很抱歉延迟回复@yakirbu事实上问题在于我的模拟器,当我使用我的手机时,它工作正常
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());
Admob.Instance().showBannerRelative("your admob banner unit id",AdSize.BANNER, AdPosition.BOTTOM_CENTER, 0);