Answer the question
In order to leave comments, you need to log in
Why doesn't banner unity ads work?
unity ads version 4.0.1, all according to the documentation. Rewarded ads work as they should on both the unit and the device. But the banner is different. In the unit itself, the banner loads quietly, but does not appear on the device. I got into the device logs, and there is an error . What does it mean and how to fix it?
Tested not on a dev build. Right now I rebuilt and checked again and the error is already another
script responsible for initialization:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
{
[SerializeField] private string _androidGameId;
[SerializeField] private string _iOSGameId;
[SerializeField] private bool _testMode;
private string _gameId;
private void Awake()
{
InitializeAds();
}
public void InitializeAds()
{
_gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOSGameId
: _androidGameId;
Advertisement.Initialize(_gameId, _testMode);
}
public void OnInitializationComplete()
{
Debug.Log("Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Ads initialization failed: {error.ToString()} - {message}");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class AdsBanner : MonoBehaviour
{
//public static AdsReward Inst;
[SerializeField] BannerPosition _bannerPosition;
[SerializeField] private string _androidAdUnitId = "Rewarded_Android";
[SerializeField] private string _iOSAdUnitId = "Rewarded_iOS";
private string _adUnitId;
private void Awake()
{
_adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOSAdUnitId
: _androidAdUnitId;
}
private void Start()
{
Advertisement.Banner.SetPosition(_bannerPosition);
StartCoroutine("LoadBannerAfterTime");
}
private IEnumerator LoadBannerAfterTime()
{
yield return new WaitForSeconds(1f);
LoadBanner();
}
public void LoadBanner()
{
BannerLoadOptions options = new BannerLoadOptions
{
loadCallback = OnBannerLoaded,
errorCallback = OnBannerError
};
Advertisement.Banner.Load(_adUnitId, options);
}
private void OnBannerLoaded()
{
Debug.Log("Banner loaded");
ShowBannerAd();
}
private void OnBannerError(string message)
{
Debug.Log($"Banner Error: {message}");
}
public void ShowBannerAd()
{
BannerOptions options = new BannerOptions
{
clickCallback = OnBannerClicked,
hideCallback = OnBannerHidden,
showCallback = OnBannerShown
};
Advertisement.Banner.Show(_adUnitId, options);
}
private void OnBannerClicked() { }
private void OnBannerShown() { }
private void OnBannerHidden() { }
public void HideBannerAd()
{
Advertisement.Banner.Hide();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question