I am using the documentation code that unity gives for using ADBannerView, but I would like the ad to go away when scene change (or switch by a Bool variable). Any ideas? Here is the code I am using.
private var banner : ADBannerView = null;
function Start () {
DontDestroyOnLoad(this);
//StartCoroutine(ShowBanner());
}
function ShowBanner() {
//var banner:ADBannerView;
banner = new ADBannerView();
banner.autoSize = true;
banner.autoPosition = ADPosition.Top;
//if(!banner.visible) print("iAdBanner : banner.visible = False");
while (!banner.loaded && banner.error == null)
yield;
if (banner.error == null)
banner.Show();
else banner = null;
}
function Update(){
if(banner==null) StartCoroutine(ShowBanner());
}
Thank you TommyB!!!
Here is the Java Script Version of your code I am using… works great, i just call “show” true or false to hide/show the iAD in various scenes.
#pragma strict
static var show : boolean = true;
private var banner : ADBannerView = null;
// do not destroy the iAD on scene switch
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
function Start () {
show = true;
}
function Update (){
if (banner == null && show == true) {
CreateBanner();
}
if(banner != null && show == false){
banner.visible = false;
banner = null;
ADBannerView.onBannerWasLoaded -= OnBannerLoaded;
}
}
function CreateBanner (){
banner = new ADBannerView(ADBannerView.Type.Banner, ADBannerView.Layout.BottomCenter);
//ADBannerView.onBannerWasClicked += OnBannerClicked;
ADBannerView.onBannerWasLoaded += OnBannerLoaded;
}
function OnBannerLoaded(){
banner.visible = true;
}