Merhaba;
Unity ile yaptığım uygulamama reklam ekledim fakat şöyle bir sorun var .
Ana sahnede reklam yok daha sonra diğer sahneye geçince reklam isteği yapıyorum ve alt tarafta banner reklam gösteriliyor fakat sonra tekrar ana sahneye gittiğimde reklamın kalkmasını istiyorum bunun için
bannerView.Destroy();
bannerView.Hide();
kodlarını kullandım fakat hiçbir türlü gitmedi...
Ne yapmam gerek ?
Kodlar:
public void Start()
{
giveReward = false;
#if UNITY_ANDROID
string appId = "ca-app-pub-3940256099942544~3347511713";
#elif UNITY_IPHONE
string appId = "ca-app-pub-3940256099942544~1458002511";
#else
string appId = "unexpected_platform";
#endif
MobileAds.SetiOSAppPauseOnBackground(true);
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(appId);
currentScene = SceneManager.GetActiveScene().name;
this.CreateAndLoadRewardedAd();
Debug.Log(currentScene);
if (currentScene == "Levels") {RequestBanner(); }
else
{
HideBanner();
}
}
public void Update()
{
// Calculate simple moving average for time to render screen. 0.1 factor used as smoothing
// value.
this.deltaTime += (Time.deltaTime - this.deltaTime) * 0.1f;
if(giveReward == true)
{
giveReward = false;
}
}
// Returns an ad request with custom ad targeting.
private AdRequest CreateAdRequest()
{
return new AdRequest.Builder()
.AddTestDevice(AdRequest.TestDeviceSimulator)
.AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
.AddKeyword("game")
.SetGender(Gender.Male)
.SetBirthday(new DateTime(1985, 1, 1))
.TagForChildDirectedTreatment(false)
.AddExtra("color_bg", "9B30FF")
.Build();
}
public void RequestBanner()
{
// These ad units are configured to always serve test ads.
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/6300978111";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/2934735716";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up banner ad before creating a new one.
if (this.bannerView != null)
{
this.bannerView.Destroy();
}
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
// Register for ad events.
this.bannerView.OnAdLoaded += this.HandleAdLoaded;
this.bannerView.OnAdFailedToLoad += this.HandleAdFailedToLoad;
this.bannerView.OnAdOpening += this.HandleAdOpened;
this.bannerView.OnAdClosed += this.HandleAdClosed;
this.bannerView.OnAdLeavingApplication += this.HandleAdLeftApplication;
// Load a banner ad.
this.bannerView.LoadAd(this.CreateAdRequest());
Debug.Log("Banner Reklam İsteği Gönderildi");
}
public void HideBanner()
{
bannerView.Destroy();
bannerView.Hide();
Debug.Log("Banner Reklam Gizlendi");
}