如何使用 Unity 广告在 Unity 中放置广告横幅?没有插件下载



我想知道如何在统一中放置广告横幅,但所有主题都是关于团结中的admobs横幅。我想知道如何使用 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"广告"不包含"横幅"的定义 ** 编辑:我让它在测试模式下工作,但是当我在手机上尝试时,什么都没有弹出。我检查了一下,这个问题已经发生在其他人身上。我住在美国,所以这个功能应该可以工作。其他人建议使用其他类型的广告。但是统一广告非常方便。

Unity 文档中的横幅广告示例:

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);
}
}

最新更新