Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by escic · Nov 15, 2013 at 10:43 AM · bannerhideflags

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


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GameVortex · Nov 15, 2013 at 11:08 AM

You can just set the visibility of the banner manually:

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

Call the function when you change your scene.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by TommyB · Apr 20, 2014 at 08:43 PM

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!\n");
     banner.visible = true;
 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ultimatearcade · May 09, 2014 at 04:41 AM

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;
         
     }
      
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dogg · Aug 26, 2014 at 02:01 AM 0
Share

From what I get from your script, you create two copies of this script, and then attach the false to a empty game object in the scene you don't want the ads to be in. As for the true you set that in every other scene right? I'm having trouble with this too.

You probably won't answer, but it's worth a try.

avatar image TommyB · Sep 01, 2014 at 08:26 PM 0
Share

@Dogg for what it's worth, I only have 1 instance of the script and it is attached to a game object in the scene I want the ads to dispaly on (which in my case is a game over scene) I don't show the ads at other times. You could in theory attach it to a single statemanger object and then have each scene set a variable on the statemanger to show or hide ads. In my C# example above the "show" variable is there to prevent multiple calls to load a banner as this was causing an exception due to trying to add multiple event handlers for the onBannerWasLoaded method. Then in my instance in the update method I have some code under Input.Get$$anonymous$$ouseButtonDown (0) that is responsible for removing the banner etc. and the event handlers if needed. Hope this helps

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hide Object in Hierarchy Window 3 Answers

GameObject HideFlags.DontSave not working as expected 1 Answer

ADBannerView sometimes doesn't disappear 0 Answers

Why does my AdMob banner not appear on my Samsung TabA? 0 Answers

Unity Banner Ads not show in first time. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges