在我目前的Unity计划中,我想要实施广告。当我运行游戏时,广告在Unity编辑器中工作,但当我尝试在iPhone 7或iPad Air上运行广告时,没有广告出现。有人知道我做错了吗?
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);
}
}
答案 0 :(得分:1)
我有同样的问题,我修复它的方式是递归功能,直到广告准备好。类似的东西:
IEnumerator ShowAd()
{
yield return new waitForSeconds(1);
if (Advertisement.IsReady())
{
Advertisement.Show ();
}
else { StartCoroutine(ShowAd()); }
}
这样,它会调用该方法,直到广告准备好展示。 此外,请确保在Unity Ads设置上启用了测试(或调试)模式。
答案 1 :(得分:0)
除了递归启动IEnumerator之外,还要添加另一个选项:
IEnumerator ShowAd()
{
while(!Advertisement.isReady())
{
yield return new waitForSeconds(1);
}
Advertisement.Show();
}