How do i hide iAd when scene change?

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());

 

}

You can just set the visibility of the banner manually:

function HideBanner()
{
   banner.visible = false;
}

Call the function when you change your scene.

I use the following for showing/hiding an ad on scene change

  using UnityEngine;
  using System.Collections;

 public class adtest : MonoBehaviour {

private ADBannerView banner= null;
private bool show = true;

void Start(){
	show = true;
}

void Update () {
	if (banner == null && show == true) {
		CreateBanner();
	}
	if (Input.GetMouseButtonDown (0)) {
		if(banner != null){
			show = false;
			banner.visible = false;
			banner = null;
			ADBannerView.onBannerWasLoaded  -= OnBannerLoaded;
		}
		Application.LoadLevel("scene1");
		
	}
}

void CreateBanner(){
	banner = new ADBannerView(ADBannerView.Type.Banner, ADBannerView.Layout.Top);
	ADBannerView.onBannerWasLoaded  += OnBannerLoaded;
}

void OnBannerLoaded()
{
	Debug.Log("Loaded!

");
banner.visible = true;
}
}

Thank you TommyB!!! :slight_smile:
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;
		
	}