编程问题.缓慢移动
本文关键字:移动 缓慢 问题 编程 | 更新日期: 2023-09-27 18:19:28
我在使用c#进行统一编程时遇到了一些问题。当我开始游戏时,我试图请求一个间隙广告,这样我就可以在玩家死亡5次时显示它。问题是,当我到了第五次死亡时,广告就不会出现了。当我尝试在关卡开始时请求广告时,它会变得滞后,仍然没有显示。
这是我的密码。这似乎是对的。
void Update(){
if (clicks >= 5) {
RequestInterstitial();
Debug.Log("Got 5 clicks");
if (interstitial.IsLoaded()){
Debug.Log("interstitial loaded");
interstitial.Show();
clicks = 0;
}
}
}
编辑:修改代码后,我现在得到错误:
NullReferenceException:对象引用未设置为对象ADS.ADMobsGameplay.Update()的实例(位于Assets/Scripts/ADS/ADMobs Gameplay.cs:28)
第28行对应于以下代码中的if (interstitial.IsLoaded()){
:
void Update(){
if (clicks >= 5) {
Debug.Log("Got 5 clicks");
if (interstitial.IsLoaded()){
Debug.Log("interstitial loaded");
interstitial.Show();
clicks = 0;
}else{
RequestInterstitial();
}
}
}
您正在一次又一次地请求Interstial。只需在程序开始时运行RequestInterstitial
方法(并确保它只运行该方法一次)。然后,在任何增加点击量的方法中,只需在末尾添加这样的内容:
int clicksRequired = 5;
int currentClicksRequired = 5;
if(clicks > currentClicksRequired){
Debug.Log("Got 5 Clicks");
if (interstitial.IsLoaded()){
Debug.Log("interstitial loaded");
interstitial.Show();
RequestInterstitial();
clicks = 0;
currentClicksRequired = clicksRequired;
}else{
Debug.Log("interstitial not loaded, skipping to next click");
currentClickRequired ++;
}
}
一旦点击达到5,它将检查间隙是否已加载。如果是,它会显示间隙,请求另一个间隙,将点击重置为0,然后继续移动。如果间隙尚未加载,它会让你等到第6次点击或第7次点击等,直到间隙加载。
首先,您在评论中显示了NullReferenceException错误:这是第一个可能提供滞后的问题。第二,在更新函数中加入一些计数逻辑真的很奇怪——更新每帧都有效——所以这是第二个可能的滞后问题。第三个Debug.Log函数不是轻量级的,进入Update函数将是第三个可能的滞后问题