Hi,
I'm developing a game in Unity.
I have three scenes:
-Menu
-Game
-GameOver
I want the Admob ad (Banner) only to display in the Menu and GameOver scenes. What is the best pratice to do that?
Destroy the ad at the end of the scene a create a new one when a scene is loaded? Or hide the ad in the Game scene?
also
My Ad Request Script is in the Menu scene does it create a
new banner every time the scene is loaded?
I'm also curious about Interstitial Ads does I need to create a specific scene for it? Or It's created automatic during the transition?
Thank You!
// FirstSceneScript.cs
void Start() {
// Create a wrapper GameObject to hold the banner. Mark the GameObject not to be destroyed when new scenes load.
GameObject myGameObject = new GameObject("myBannerAdObject");
myGameObject.AddComponent<BannerWrapper>();
DontDestroyOnLoad(myGameObject);
}
// BannerWrapper.cs
using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class BannerWrapper : MonoBehaviour {
public BannerView bannerView;
void Start()
{
bannerView = new BannerView("your_ad_unit_id", AdSize.SmartBanner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder().Build();
bannerView.LoadAd (request);
bannerView.Show();
}
}
// SecondSceneScript.cs
void Start () {
GameObject myGameObject = GameObject.Find("myBannerAdObject");
BannerWrapper bannerWrapper= myGameObject.GetComponent<BannerWrapper>();
bannerWrapper.bannerView.Hide();
}
Thank you Ram!