如何使用 Unity ads 统一放置广告横幅?没有插件下载
How to place a ad banner in unity using Unity ads? No plugins download
我想弄清楚如何统一放置广告横幅,但所有主题都是关于统一的 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 'Advertisement' 不包含 'Banner' 的定义
**
编辑:我让它在测试模式下工作,但是当我在 phone 上尝试它时,没有弹出任何内容。我查了一下,这个问题已经发生在其他人身上。我住在美国,所以这个功能应该可以用。其他人建议使用其他类型的广告。但是unity ads很方便。
中的横幅广告示例
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);
}
}
我想弄清楚如何统一放置广告横幅,但所有主题都是关于统一的 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 'Advertisement' 不包含 'Banner' 的定义 ** 编辑:我让它在测试模式下工作,但是当我在 phone 上尝试它时,没有弹出任何内容。我查了一下,这个问题已经发生在其他人身上。我住在美国,所以这个功能应该可以用。其他人建议使用其他类型的广告。但是unity ads很方便。
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); } }