我对 Unity 测试广告没有任何问题,它们在 Android 版本上显示良好,没有错误。
但是当我接近发布时,我在编辑器中关闭了“测试模式”,现在我的代码中对广告的所有引用突然在当前上下文中不存在。
错误:
Assets\Scripts\AdManager.cs(32,21): error CS0103: The name 'Advertisement' does not exist in the current context
我在网上没有找到任何关于这个的东西,我真的很困惑。尝试了“关闭广告,重新打开统一,打开广告”,但它并没有摆脱错误。
这是我的代码:
using UnityEngine;
using UnityEngine.Advertisements;
public class AdManager : MonoBehaviour
{
public void ShowAd(int roundScore){
Debug.Log("Recieved request to display an ad");
Debug.Log(roundScore);
if(roundScore >= 40){
Debug.Log("Trying to show an ad because score is larger than 40");
// Check for ad + show it
if(Advertisement.IsReady("video")){
Advertisement.Show("video");
}
}else{
Debug.Log("Trying to show a random ad");
if(Random.Range(0, 7) == 4){
Debug.Log("Random ad will be shown if ready");
//Check for ad + show it
if(Advertisement.IsReady("video")){
Debug.Log("An ad was ready so it is being shown");
Advertisement.Show("video");
}
}
}
}
}
谢谢您的帮助。