问题描述
我想要这样的东西
static int loadCount = 0;
void Start()
{
if (loadCount == 3)
{
loadCount = 0;
AdManager.setActive(true);
}
else
{
loadCount++;
AdManager.setActive(false);
}
}
广告管理器是我拥有的另一个脚本的名称
解决方法
您的代码应该可以按预期工作,但是问题是当您卸载场景时,您的gameObject被删除了。当gameObject被删除时,其所有数据都将被删除(因此,每次加载场景时loadCount将重置为0)。因此,您必须使gameObject在卸载时不被破坏。这应该是您需要的代码:
int loadCount = 0;
void Start()
{
gameObject.DontDestroyOnLoad();
if (loadCount == 3)
{
loadCount = 0;
AdManager.setActive(true);
}
else
{
loadCount++;
AdManager.setActive(false);
}
}