Admob广告未在Unity中显示,C#

问题描述 投票:0回答:1

[我的Admob广告没有显示在Android上的应用中,我尝试了所有操作,不同版本的统一性,广告类型,重新安装admob插件,针对Android编译的播放器设置的不同组合。

登录Unity(我在Android上进行了测试):

Dummy已加载假人ShowIntertitial

代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using GoogleMobileAds.Api;

public class ControllerMain : MonoBehaviour
{

public Button LV1, LV2, LV3, LV4, LV5, LV6, LV7, LV8, LV9, LV10;
public int ReturnedVal;
private string MyIdA = "ca-app-pub-3940256099942544/1033173318";
//private InterstitialAd fullscreenad;
//private string FullScreenID = "ca-app-pub-3940256099942544/1033173651";
//private BannerView bannerView;
private InterstitialAd InterFULLSC;
void LOV1() {
    SceneManager.LoadScene(1);
}
void LOV2()
{
    SceneManager.LoadScene(2);
}
void LOV3()
{
    SceneManager.LoadScene(3);
}
void LOV4()
{
    SceneManager.LoadScene(4);
}
void LOV5()
{
    SceneManager.LoadScene(5);
}
void LOV6()
{
    SceneManager.LoadScene(6);
}
void LOV7()
{
    SceneManager.LoadScene(7);
}
void LOV8()
{
    SceneManager.LoadScene(8);
}
void LOV9()
{
    SceneManager.LoadScene(9);
}
void LOV10()
{
    SceneManager.LoadScene(10);
}
// Start is called before the first frame update
void Start()
{
    MobileAds.Initialize(initStatus => { });
    this.InterFULLSC = new InterstitialAd(MyIdA);
    //LV1.GetComponent<Image>().color = Color.black;
    ReturnedVal = GameMonitor.IsPassed;
    if (ReturnedVal > 0)
    {
        AdRequest requ = new AdRequest.Builder().Build();
        this.InterFULLSC.LoadAd(requ);

        if (this.InterFULLSC.IsLoaded()) {
            this.InterFULLSC.Show();
        }
        //MobileAds.Initialize(appID);
        //go
        //bannerView = new BannerView("ca-app-pub-3940256099942544/6300978111", AdSize.Banner, AdPosition.Bottom);
        //AdRequest requ = new AdRequest.Builder().Build();
        //bannerView.LoadAd(requ);
        //bannerView.Show();
        //end
        //fullscreenad = new InterstitialAd(FullScreenID);
        //AdRequest request = new AdRequest.Builder().Build();
        //fullscreenad.LoadAd(request);
        //if (fullscreenad.IsLoaded())
        //{
        //    fullscreenad.Show();
        //}
        //else { Debug.Log("Didn't load"); }

    }
    Debug.Log(ReturnedVal);
    LV1.GetComponent<Image>().color = Color.green;
    LV2.GetComponent<Image>().color = Color.black;
    LV3.GetComponent<Image>().color = Color.black;
    LV4.GetComponent<Image>().color = Color.black;
    LV5.GetComponent<Image>().color = Color.black;
    LV6.GetComponent<Image>().color = Color.black;
    LV7.GetComponent<Image>().color = Color.black;
    LV8.GetComponent<Image>().color = Color.black;
    LV9.GetComponent<Image>().color = Color.black;
    LV10.GetComponent<Image>().color = Color.black;
    LV2.interactable = false;
    LV3.interactable = false;
    LV4.interactable = false;
    LV5.interactable = false;
    LV6.interactable = false;
    LV7.interactable = false;
    LV8.interactable = false;
    LV9.interactable = false;
    LV10.interactable = false;
    LV1.interactable = true;
    LV1.onClick.AddListener(LOV1);
    if (ReturnedVal == 2 || ReturnedVal>2) {
        LV2.interactable = true;
        LV2.GetComponent<Image>().color = Color.green;
        LV2.onClick.AddListener(LOV2);
    }
    if (ReturnedVal == 3 || ReturnedVal > 3)
    {
        LV3.interactable = true;
        LV3.GetComponent<Image>().color = Color.green;
        LV3.onClick.AddListener(LOV3);
    }
    if (ReturnedVal == 4 || ReturnedVal > 4)
    {
        LV4.interactable = true;
        LV4.GetComponent<Image>().color = Color.green;
        LV4.onClick.AddListener(LOV4);
    }
    if (ReturnedVal == 5 || ReturnedVal > 5)
    {
        LV5.interactable = true;
        LV5.GetComponent<Image>().color = Color.green;
        LV5.onClick.AddListener(LOV5);
    }
    if (ReturnedVal == 6 || ReturnedVal > 6)
    {
        LV6.interactable = true;
        LV6.GetComponent<Image>().color = Color.green;
        LV6.onClick.AddListener(LOV6);
    }
    if (ReturnedVal == 7 || ReturnedVal > 7)
    {
        LV7.interactable = true;
        LV7.GetComponent<Image>().color = Color.green;
        LV7.onClick.AddListener(LOV7);
    }
    if (ReturnedVal == 8 || ReturnedVal > 8)
    {
        LV8.interactable = true;
        LV8.GetComponent<Image>().color = Color.green;
        LV8.onClick.AddListener(LOV8);
    }
    if (ReturnedVal == 9 || ReturnedVal > 9)
    {
        LV9.interactable = true;
        LV9.GetComponent<Image>().color = Color.green;
        LV9.onClick.AddListener(LOV9);
    }
    if (ReturnedVal == 10)
    {
        LV10.interactable = true;
        LV10.GetComponent<Image>().color = Color.green;
        LV10.onClick.AddListener(LOV10);
    }
    }

    // Update is called once per frame
    void Update()
    {


    }
    }
c# android unity3d admob ads
1个回答
0
投票
您必须使用以下格式初始化广告:

MobileAds.Initialize(appID);

此外,您还尝试在开始功能中一起加载和展示广告,这可能是您所面临问题的原因之一。在开始功能中加载广告,但通过调用以下功能,在单击任何按钮时显示广告]

void ShowAd(){ if (this.InterFULLSC.IsLoaded()) { this.InterFULLSC.Show(); } }

© www.soinside.com 2019 - 2024. All rights reserved.