I am developing a game and i implement a startapp ad plugin in that. I used a banner ad in my scene but after some user input i want to remove or hide that banner from scene so how i remove/hide that startapp banner?
Please reply me if anyone have an idea of this
Thanks in advance…
If the banner is being contained within it’s own GameObject, you can keep a reference to the object and use the SetActive method to disable or enable it at will. If it is a component, you again should reference or retrieve with the GetComponent template and set the enabled/active flag from there.
Well, i create one prefab object with the banner ad script, and try to add that in screen on runtime and destroy where i want to hide, but can’t succeed.
Also try to remove that gameobject from scene in runtime.
So if you done that can you give me little detailed solution for that?
I apologize, but without being able to see the code you are using currently there isn’t a whole lot more that I can do than explain the principle concepts behind a possible solution.
Currently I have a single game object on my main menu [called androidAdBanner"] that contains the prebuilt StartApp script that came with the SDK. Looks like this:
using UnityEngine;
using System.Collections;
using StartApp;
public class SmartAppBanner : MonoBehaviour {
// Use this for initialization
void Start () {
StartAppWrapper.addBanner (
StartAppWrapper.BannerType.AUTOMATIC,
StartAppWrapper.BannerPosition.TOP);
}
}
But I just want to hide it on a particular game scene.
I tried something similar to what lorenalexm said. I used GameObject.active = false but that didn’t work when I ran a test on the actual device. All it seemed to do was lag me and freeze my game, but I’ll try it again one more time. If anyone has any suggestions, please feel free to share them. Don’t worry, I won’t bite you.
Yes I did. Okay here’s how i did it. First take a look at this script:
public class AdtestGone : MonoBehaviour {
private ADBannerView banner= null;
private bool show = true;
bool hide = false;
void Start(){
show = true;
}
void Update () {
if (banner == null && show == true) {
CreateBanner ();
}
if (hide == true) {
Debug.Log("Hide");
if (banner != null) {
show = false;
banner.visible = false;
banner = null;
ADBannerView.onBannerWasLoaded -= OnBannerLoaded;
}
}
}
void CreateBanner(){
banner = new ADBannerView(ADBannerView.Type.Banner, ADBannerView.Layout.Bottom);
ADBannerView.onBannerWasLoaded += OnBannerLoaded;
}
public void HideBanner()
{
Debug.Log ("HideBanner");
hide = true;
}
void OnBannerLoaded()
{
Debug.Log("Loaded!\n");
banner.visible = true;
}
}
This is the script I use for my ads. I recommend using it. Okay so next I drag this script onto an empty game object in the scene that I want it to appear in. I chose the main menu to display my ads. So I have three GUI buttons that take me to different scenes. In the main menu script where the GUI buttons are, I do this:
public AdtestGone other;
void OnGUI(){
if (GUI.Button (new Rect (Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .5f, Screen.height * .1f), "Play Game")) {
other.HideBanner();
Application.LoadLevel ("Level1");
I tell the script to hide the banner, and it does. Call other.HideBanner() every time you want to hide your banner. Test it out on your device and see if it works for you. It worked for me, and my game is now on the App Store. Hope this helps you.