c# - 'Advertisement' 类型存在于 'UnityEngine.Advertisements.Editor' 中

标签 c# unity3d compiler-errors ads

我正在使用 Unity Ads 在 Unity 2019.2.21f1 中构建带有广告的游戏。我有以下用于显示广告的简短脚本:

using System.Collections;
using UnityEngine;
using UnityEngine.Advertisements;

public class AdBannerScriptUnity : MonoBehaviour
{
    public string gameId = "myGameId";
    public string placementId = "AdBanner";
    public bool testMode = true;

    void Start()
    {
        Advertisement.Initialize(gameId, testMode);
        StartCoroutine(ShowBannerWhenReady());
    }

    IEnumerator ShowBannerWhenReady()
    {
        while (!Advertisement.IsReady(placementId))
        {
            yield return new WaitForSeconds(0.5f);
        }
        Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
        Advertisement.Banner.Show(placementId);
    }
}

我在 Unity 服务(Unity 编辑器 UI 右上角的云图标按钮)中启用了广告,并从 Assets 商店导入了 Unity 货币化 Assets 。

在构建这个游戏时,我收到以下错误:
Assets/Scripts/AdBannerScriptUnity.cs(13,9): error CS0433: The type 'Advertisement' exists in both 'UnityEngine.Advertisements.Editor, Version=3.4.2.0, Culture=neutral, PublicKeyToken=null' and 'UnityEngine.Advertisements, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

我在某处读到过,从 Unity 5.2 开始,Unity 货币化 Assets 不再需要用 Unity 显示广告,所以我尝试删除它,但后来我得到了
Assets/Scripts/AdBannerScriptUnity.cs(23,23): error CS0117: 'Advertisement' does not contain a definition for 'Banner'

很明显, Assets 是必要的,但似乎我不知何故,根据上面发布的第一个错误,安装了两个版本?如何确保我只安装了一个版本?

最佳答案

我正在使用 Unity 2019.3 6f1 并遇到同样的问题。我在某处读到,如果您使用商店中的货币化 Assets 并启用来自 Unity 服务的广告,则会产生问题。但我无法删除 Assets 。当我从服务中禁用广告时,不再显示广告(自然安静:))所以寻找该帖子的更新。

编辑:伙计,我终于解决了我的问题。事实上,正是 Assets 商店的货币化 Assets 导致了冲突。您应该使用服务选项卡中的广告并从包管理器(而不是 Assets 商店)导入货币化 Assets ,并从 Assets 商店中删除货币化的所有内容。我附上了您应该从项目文件夹中删除的文件的图像。
Unity Monetization Asset Store Files

关于c# - 'Advertisement' 类型存在于 'UnityEngine.Advertisements.Editor' 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61377566/

相关文章:

c++ - 初始化列表不工作 xCode 4.4

c# - 使用结构 union 将 C++ 编码到 C# 结构

c# - 如何使用 Linq 获取随机对象

c# - 为什么 Mono 不能支持 AOT 的通用接口(interface)实例化?

c# - 如何将四元数旋转转换为方向盘运动?

android - Unity 导出带有 Facebook SDK 问题的 android 项目

c# - 如何检测是否按下了任何键盘功能键?

c# - 将链接标签添加到绑定(bind)到 DataSet 的 DataGridView 单元格或列

android - 编译android 4.0.3时找不到-ltinfo

swift - xcode8 Alamofire 4更新错误 "use of undeclared type Response"