我正在使用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右上角的云图标按钮),并从资源商店导入了Unity货币化资产。
在构建这个游戏时,我得到了以下错误:
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货币化资产不再需要使用Unity显示广告,所以我尝试删除它,但后来我得到了
Assets/Scripts/AdBannerScriptUnity.cs(23,23): error CS0117: 'Advertisement' does not contain a definition for 'Banner'显然,Asset是必要的,但根据上面发布的第一个错误,我似乎以某种方式安装了两个版本?如何确保我只安装了一个版本?
发布于 2020-05-11 20:31:55
我正在使用Unity 2019.3 6f1,并且遇到了同样的问题。我在某处读到,如果你使用商店的货币化资产,并启用Unity Services的广告,他们就会产生问题。但我不能移走资产。当我从服务中禁用广告时,将不再显示任何广告(自然安静:),因此请查找该帖子的更新。
编辑: Mate,我终于解决了我的问题。事实上,正是资产商店的货币化资产导致了冲突。您应该使用服务选项卡中的广告,从包管理器(而不是从资产存储)导入货币化资产,并从资产存储中删除货币化的所有内容。我附上了你应该从你的项目文件夹中删除的文件的图像。Unity Monetization Asset Store Files
发布于 2020-08-18 21:30:22
我也犯过同样的错误。它出现在我的项目中有"Advertisement“package form Package manager和Asset store "Unity Monetization”的时候。所以,我删除了"Unity Monetization“,然后错误就消失了。
在Unity 2019.3.14f1上使用了它,它仍然在Unity 2020.1.2f1上工作。我认为当我第一次在Services标签的项目设置中启用广告时,包管理器安装了"Advertisement“包。
编辑:在unity 2020.1.2f1中,Asset store已从Unity中删除,但您仍然可以在浏览器中打开它,并且您可以从Package manager导入您的资产商店购买:D
https://stackoverflow.com/questions/61377566
复制相似问题