1

我开发了一个统一的游戏,我在我的游戏中放置了 Unity 广告,但我Advertisement.IsReady()总是返回false

私有字符串 AndroidGameId = "xxxxx";

  public void ShowRewardVideo()
    {
        if (Application.internetReachability != NetworkReachability.NotReachable)
        {
            if (Advertisement.IsReady())
            {
                Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleReward });
            }
            else
            {
                VideoLoadingUI.SetActive(true);
                if (!Advertisement.isInitialized)
                {
                    Advertisement.Initialize(AndroidGameId, false);
                }
                StartCoroutine(waitAdLoad());
            }
        }
        else
        {
            LoadInternetFaildUI.SetActive(true);
        }
    }
    private void HandleReward(ShowResult result)
    {
        switch (result)
        {
            case ShowResult.Finished:
                AddLifes(1);
                break;
            case ShowResult.Skipped:
                Advertisement.Initialize(AndroidGameId, false);
                break;
            case ShowResult.Failed:
                VideoLoadingUI.SetActive(false);
                VideoLoadingUIFaild.SetActive(true);
                Advertisement.Initialize(AndroidGameId, false);
                break;
        }
    }
    IEnumerator waitAdLoad()
    {
        for (int i = 0; i <= 5; i++)
        {
            yield return new WaitForSeconds(1f);

            if (Advertisement.IsReady())
            {
                break;
            }
        }
        VideoLoadingUI.SetActive(false);
        if (Advertisement.IsReady())
        {
            Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleReward });
        }
        else
        {
           VideoLoadingUIFaild.SetActive(true);
            if (!Advertisement.isInitialized)
            {
                Advertisement.Initialize(AndroidGameId, false);
            }
        }
    }

有谁知道为什么会这样?

4

0 回答 0