我想弄清楚如何统一放置广告横幅,但是所有主题都是关于统一横幅的。我想知道如何使用Unity广告横幅。
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Advertisements;
using UnityEngine;
public class UnityAdManager : MonoBehaviour
{
public string gameId = "gameid";
public string placementId = "Adbanner";
public bool testMode = true;
public static UnityAdManager instance;
void Awake()
{
DontDestroyOnLoad(this.gameObject);
if (instance == null)
{
instance = this;
}
else
{
Destroy(this.gameObject);
}
}
// Start is called before the first frame update
void Start()
{
Advertisement.Initialize(gameId, testMode);
StartCoroutine(ShowBannerWhenReady());
}
// Update is called once per frame
void Update()
{
}
public void ShowAd()
{
if (PlayerPrefs.HasKey("Adcount"))
{
//number of ads
if (PlayerPrefs.GetInt("Adcount") == 2)
{
if (Advertisement.IsReady("video"))
{
Advertisement.Show("video");
}
PlayerPrefs.SetInt("Adcount", 0);
}
else
{
PlayerPrefs.SetInt("Adcount", PlayerPrefs.GetInt("Adcount") + 1);
}
}
else
{
PlayerPrefs.SetInt("Adcount", 0);
}
}
IEnumerator ShowBannerWhenReady()
{
while (!Advertisement.IsReady(placementId))
{
yield return new WaitForSeconds(0.5f);
}
Advertisement.Banner.Show(placementId);
}
}
**我不断收到错误消息
错误CS0117“广告”不包含“横幅”的定义 ** 编辑:我让它在测试模式下工作,但是当我在手机上尝试时,什么都没有弹出。我检查了一下,这个问题已经发生在其他人身上。我住在美国,因此此功能应该可以使用。其他人建议使用其他类型的广告。但是统一广告非常方便。
答案 0 :(得分:0)
using System.Collections; using UnityEngine; using UnityEngine.Advertisements; public class BannerAdScript : MonoBehaviour { public string gameId = "1234567"; public string placementId = "bannerPlacement"; public bool testMode = true; void Start () { Advertisement.Initialize (gameId, testMode); StartCoroutine (ShowBannerWhenReady ()); } IEnumerator ShowBannerWhenReady () { while (!Advertisement.IsReady (placementId)) { yield return new WaitForSeconds (0.5f); } Advertisement.Banner.Show (placementId); } }