【问题标题】:Admob ads are not showing in Unity, C#Admob 广告未在 Unity、C# 中显示
【发布时间】:2019-11-10 18:47:49
【问题描述】:

我的 Admob 广告没有在我的 Android 应用中显示,我尝试了所有方法,不同版本的 unity、广告类型、重新安装 admob 插件、用于 android 编译的播放器设置的不同组合。

登录Unity(我在Android上测试过)是:

虚拟已加载
虚拟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】:

    使用以下格式初始化广告:

    MobileAds.Initialize(appID);
    

    您还尝试在启动功能中一起加载和显示广告,这可能是您遇到问题的原因之一。 在启动函数中加载广告,但通过调用以下函数在任何按钮点击时显示广告

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

    【讨论】:

    • 感谢您的反馈,但很遗憾没有帮助。
    • 使用测试应用 ID 并测试插页式广告 ID 并检查一次。不要使用实时广告 ID
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 2021-11-04
    相关资源
    最近更新 更多