Make AdBannerView not show when changing scenes

I would like to make the AdBannerView not show when leaving the main menu scene in my Unity application. The example in the documentation works and correctly shows an ad on my main menu scene. When navigating to another scene the ad will still be shown on the screen. How do you programmatically dismiss or get rid of an AdBannerView. I have tried the obvious solution of setting the banner object to null in the OnDestroy event.

Documentation link:
http://docs.unity3d.com/Documentation/ScriptReference/ADBannerView.html

Um… banner.visible = false?

Hi Southern Coder,

If I add

void OnDestroy()
{
banner.visible = false;
}

Then I have the problem of showing the AdBanner again when you come back to the main menu scene.

I had this exact same issue and I think I’ve resolved it. I use the following code in a script attached to a gameObject in the scene where i want to show an ad

using UnityEngine;
using System.Collections;

public class adtest : MonoBehaviour {


	private ADBannerView banner= null;
	private bool show = true;  // this extra boolean is used just to ensure that the banner won't get recreated in the update() function after it has been destroyed but before the next scene has been loaded

	void Start(){
		show = true;
	}

	void Update () {
		if (banner == null  show == true) {
			CreateBanner();
		}
		if (Input.GetMouseButtonDown (0)) {
			show = false;
			banner.visible = false;
			banner = null;
			ADBannerView.onBannerWasLoaded  -= OnBannerLoaded; // Very important that this is called
			Application.LoadLevel("scene1");
			
		}
	}

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

	void OnBannerLoaded()
	{
		Debug.Log("Loaded!\n");
		banner.visible = true;

}

}