Why won't any of these iAD scripts do what I want? I'm trying to hide the banners when I click a GUI Button. It actually seems to work when i test it on my game, but after a couple of clicks later it stops hiding and stays there(which is a HUGE problem). My developer settings fill rate is set to 50%, but even in other percentages it still doesn't hide constantly. So what's the problem here? What am I'm missing or doing wrong? Please help. Here's my GUI menu script:
public class MainMenu : MonoBehaviour {
public adtest other;
public float guiPlacementY1;
public float guiPlacementY2;
public float guiPlacementY3;
public float guiPlacementX1;
public float guiPlacementX2;
public float guiPlacementX3;
void OnGUI(){
if (GUI.Button (new Rect (Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .5f, Screen.height * .1f), "Menu1")) {
other.HideBanner();
Application.LoadLevel ("Menu1");
}
if (GUI.Button (new Rect (Screen.width * guiPlacementX3, Screen.height * guiPlacementY3, Screen.width * .3f, Screen.height * .1f), "Menu2")) {
Application.LoadLevel ("Menu2");
}
if (GUI.Button (new Rect (Screen.width * guiPlacementX2, Screen.height * guiPlacementY2, Screen.width * .5f, Screen.height * .1f), "Menu3")) {
Application.LoadLevel ("Menu3");
}
}
}
iAD Banner script:
public class adtest : 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("WHY WONT YOU WORK?");
if (banner != null) {
show = false;
banner.visible = false;
banner = null;
ADBannerView.onBannerWasLoaded -= OnBannerLoaded;
}
Application.LoadLevel("Menu2");
}
}
void CreateBanner(){
banner = new ADBannerView(ADBannerView.Type.Banner, ADBannerView.Layout.Top);
ADBannerView.onBannerWasLoaded += OnBannerLoaded;
}
public void HideBanner()
{
Debug.Log ("HideBanner");
hide = true;
}
void OnBannerLoaded()
{
Debug.Log("Loaded!\n");
banner.visible = true;
}
}
I also have another ad script I used to use. it pretty much worked the same as the script posted here. I will post it soon.
Quick Update: So I ran some more test, it appears that it does work, BUT ONLY when I don't click any of the other GUI Buttons. The script I posted isn't is the full script, so I've updated it. If you have any suggestions please feel free to help, please.
↧