C# Unity广告在真实设备上不起作用
在我目前的Unity程序中,我想实现广告。当我运行游戏时,这些广告在Unity编辑器中确实起作用,但当我尝试在我的iPhone 7或iPad Air上运行广告时,没有广告出现。有人知道我做错了什么吗C# Unity广告在真实设备上不起作用,c#,ios,visual-studio,unity3d,ads,C#,Ios,Visual Studio,Unity3d,Ads,在我目前的Unity程序中,我想实现广告。当我运行游戏时,这些广告在Unity编辑器中确实起作用,但当我尝试在我的iPhone 7或iPad Air上运行广告时,没有广告出现。有人知道我做错了什么吗 using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.Advertisements; public class GameManager : MonoBehaviour { void Start() {
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Advertisements;
public class GameManager : MonoBehaviour
{
void Start()
{
Advertisement.Initialize("Appstore-id");
}
bool gameHasEnded = false;
public float restartDelay = 1f;
public float addDelay = 1f;
public GameObject completeLevelUI;
public void CompleteLevel ()
{
completeLevelUI.SetActive(true);
Invoke("ShowAdd", addDelay);
}
public void EndGame()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("Game over");
Invoke("Restart", restartDelay);
}
}
public void ShowAdd()
{
if (Advertisement.IsReady())
{
Advertisement.Show ();
}
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
我也有同样的问题,我修复它的方法是递归函数,直到ad就绪。比如:
IEnumerator ShowAd()
{
yield return new waitForSeconds(1);
if (Advertisement.IsReady())
{
Advertisement.Show ();
}
else { StartCoroutine(ShowAd()); }
}
这样,它将调用该方法,直到广告准备好显示为止。
另外,确保在Unity Ads设置上启用了测试(或调试)模式。除了递归启动IEnumerator外,只需添加另一个选项:
IEnumerator ShowAd()
{
while(!Advertisement.isReady())
{
yield return new waitForSeconds(1);
}
Advertisement.Show();
}
谢谢您的快速回答,我将尝试一下,看看它是否也适用于mee。即使我将其更改为ShowAdd@GriffinTeurlings不是调用invoke,而是调用
startcroutine
吗?[与问题无关]:@Mykod如果返回ShowAd()就足够了代码>在else块中,因为此时我们已经在一个协同程序中了?我刚刚测试了广告在安装了我的项目版本后是否在我的手机上工作,但它们仍然不工作。我还注意到的另一件事是,我的暂停菜单中的UIButtons在我的手机上也不起作用,但它们在Unity编辑器中起作用。@EddgeInvoke
使用第二个参数,它指示在调用方法之前(至少)应该经过多少时间。@AndreasBjørnHassingNielsen yea我意识到了,哈哈