问题描述
所以我正在努力将统一广告添加到我的 android 游戏中……我是根据 UNITY 的 过时 统一教程完成的
我的问题是,当我想在 android 上获得“unity's2D 测试广告”时,它们不会出现在 PC 或 Remote 5 上
我的代码是什么:
using System.Collections;
using UnityEngine;
using UnityEngine.Advertisements;
public class AdManager : MonoBehavIoUr
{
IEnumerator Start()
{
Advertisement.Initialize("xxxxxxx",true);
while(!Advertisement.IsReady())
yield return null;
Advertisement.Show();
}
}
我的错误是什么:
IT DOESNT GIVE ME ONE
请帮帮我
解决方法
正如我在评论中提到的,您需要从问题中删除您的 ID,并可能请求新的 ID。我相信您的问题是您从不调用此 IEnumerator
。调用它 Start
没有任何作用,因为 Monobehaviours
期望在 Unity 的默认执行中调用 void
类型的函数。
只需调用 IEnumerator
private void Start()
{
Advertisement.Initialize("xxxxxxxx",true);
StartCoroutine(StartAd());
}
private void StartAd()
{
while(!Advertisement.IsReady())
yield return null;
Advertisement.Show();
}
我会考虑存储对 Coroutine
调用的引用,这样您就不会尝试同时投放两个广告,但由于您的示例是从 Start
调用的,因此它只会被调用一个现在,所以这不是问题。