c# - Delete admob by deleting gameobject. not working -
i new unity. made application , decide add advertisement it. user can delete advertisement when clicked button. put googlemobileadsdemoscript gameobject , button destroy gameobject when user click it. problem is.. not working. gameobject deleted advertisement still there. can guys me.. heres code. renamed disablead.cs
using system; using unityengine; using googlemobileads; using googlemobileads.api; public class disablead : monobehaviour { private bannerview bannerview; private interstitialad interstitial; private static string outputmessage = ""; void awake() { requestbanner(); } public static string outputmessage { set { outputmessage = value; } } void requestbanner() { if(playerprefs.haskey("adfree")) return; #if unity_editor string adunitid = "unused"; #elif unity_android string adunitid = "ca-app-pub-3110192020641644/9651420212"; #elif unity_iphone string adunitid = "insert_ios_banner_ad_unit_id_here"; #else string adunitid = "unexpected_platform"; #endif // create 320x50 banner @ top of screen. bannerview = new bannerview(adunitid, adsize.smartbanner, adposition.top); // register ad events. bannerview.adloaded += handleadloaded; bannerview.adfailedtoload += handleadfailedtoload; bannerview.adopened += handleadopened; bannerview.adclosing += handleadclosing; bannerview.adclosed += handleadclosed; bannerview.adleftapplication += handleadleftapplication; // load banner ad. bannerview.loadad(createadrequest()); } void removeads() { if (playerprefs.haskey("adfree")) print("ads removed"); else{ playerprefs.setint("adfree", 1); playerprefs.save(); // destroy/disable ad objects here } } //void restorepurchases() //{ // if (isproductpurchased("productid")) // removeads(); //} private void requestinterstitial() { #if unity_editor string adunitid = "unused"; #elif unity_android string adunitid = "ca-app-pub-3110192020641644/2128153413"; #elif unity_iphone string adunitid = "insert_ios_interstitial_ad_unit_id_here"; #else string adunitid = "unexpected_platform"; #endif // create interstitial. interstitial = new interstitialad(adunitid); // register ad events. interstitial.adloaded += handleinterstitialloaded; interstitial.adfailedtoload += handleinterstitialfailedtoload; interstitial.adopened += handleinterstitialopened; interstitial.adclosing += handleinterstitialclosing; interstitial.adclosed += handleinterstitialclosed; interstitial.adleftapplication += handleinterstitialleftapplication; googlemobileadsdemohandler handler = new googlemobileadsdemohandler(); interstitial.setinapppurchasehandler(handler); // load interstitial ad. interstitial.loadad(createadrequest()); } // returns ad request custom ad targeting. private adrequest createadrequest() { return new adrequest.builder() .addtestdevice(adrequest.testdevicesimulator) .addtestdevice("0123456789abcdef0123456789abcdef") .addkeyword("game") .setgender(gender.male) .setbirthday(new datetime(1985, 1, 1)) .tagforchilddirectedtreatment(false) .addextra("color_bg", "9b30ff") .build(); } private void showinterstitial() { if (interstitial.isloaded()) { interstitial.show(); } else { print("interstitial not ready yet."); } } #region banner callback handlers public void handleadloaded(object sender, eventargs args) { bannerview.show (); print("handleadloaded event received."); } public void handleadfailedtoload(object sender, adfailedtoloadeventargs args) { print("handlefailedtoreceivead event received message: " + args.message); } public void handleadopened(object sender, eventargs args) { print("handleadopened event received"); } void handleadclosing(object sender, eventargs args) { print("handleadclosing event received"); } public void handleadclosed(object sender, eventargs args) { print("handleadclosed event received"); } public void handleadleftapplication(object sender, eventargs args) { print("handleadleftapplication event received"); } #endregion #region interstitial callback handlers public void handleinterstitialloaded(object sender, eventargs args) { print("handleinterstitialloaded event received."); } public void handleinterstitialfailedtoload(object sender, adfailedtoloadeventargs args) { print("handleinterstitialfailedtoload event received message: " + args.message); } public void handleinterstitialopened(object sender, eventargs args) { print("handleinterstitialopened event received"); } void handleinterstitialclosing(object sender, eventargs args) { print("handleinterstitialclosing event received"); } public void handleinterstitialclosed(object sender, eventargs args) { print("handleinterstitialclosed event received"); } public void handleinterstitialleftapplication(object sender, eventargs args) { print("handleinterstitialleftapplication event received"); } #endregion }
and button script
public void removead() { destroy (gameobject.find ("advertistment")); application.loadlevel ("minigame");//this replay game } }
maybe should use script instead of deleting it.
try calling:
gameobject.find ("advertistment").getcomponent<disablead>().removeads();
of course add null
checking.
Comments
Post a Comment