android - Unity: Admob Reward Video Ad Doesn't Call Events -
i'm trying add admob reward video ad android game made in unity. displays fine when close ad, reward never given. i've tested code in function , works fine think problem is isn't gettting called. can me?
using unityengine; using unityengine.ui; using system.collections; using system; using googlemobileads; using googlemobileads.api; public class textedit : monobehaviour { public image lifeadui; static image lifeaduistat; public text adfailui; static text adfailuistat; public button lifebutton; private static rewardbasedvideoad videoad; static bool adtime = false; static bool adplaying = false; static int pass = 0; bool watched; // use initialisation void start() { button btn = lifebutton.getcomponent<button>(); btn.onclick.addlistener(videoad); videoad = rewardbasedvideoad.instance; videoad.onadfailedtoload += handleonadfailedtoload; videoad.onadopening += handleonadopening; videoad.onadclosed += handleonadclosed; videoad.onadrewarded += handleonadreward; videoad.onadleavingapplication += handleonadleavingapplication; videoad.onadloaded += handleonadloaded; videoad.onadstarted += handleonadstarted; lifeaduistat = lifeadui; adfailuistat = adfailui; } public static void loadvideoad() { #if unity_editor string adunitid = "unused"; #elif unity_android string adunitid = "ca-app-pub-3025391748532285/9122766975"; #elif unity_iphone string adunitid = ""; #else string adunitid = "unexpected_platform"; #endif videoad.loadad(new adrequest.builder().build(), adunitid); pass = pass + 1; } void videoad() { if (videoad.isloaded()) { videoad.show(); } else { //ad not loaded } } //ad events public void handleonadfailedtoload(object sender, adfailedtoloadeventargs args) { if (pass < 2) { loadvideoad(); } else { startcoroutine(adfailcoro()); } } public void handleonadopening(object ssender, eventargs args) { adplaying = true; } public void handleonadclosed(object sender, eventargs args) { adplaying = false; watched = true; if (watched == true) { control controlscript = gameobject.findgameobjectwithtag("control").getcomponent<control>(); lifeadui.enabled = false; startcoroutine(controlscript.extralife()); } } public void handleonadreward(object sender, eventargs args) { watched = true; } public void handleonadleavingapplication(object sender, eventargs args) { } public void handleonadloaded(object sender, eventargs args) { } public void handleonadstarted(object sender, eventargs args) { } }
if called videoad
show video ad due unforeseen reason video not loaded yet, or having loading failure, request load ad again.
void videoad() { if (videoad.isloaded()) { videoad.show(); } else { loadvideoad(); } }
request load new video ad when ad closed user.
public void handleonadclosed(object sender, eventargs args) { adplaying = false; watched = true; if (watched == true) //what need of condition, true { control controlscript = gameobject.findgameobjectwithtag("control").getcomponent<control>(); lifeadui.enabled = false; startcoroutine(controlscript.extralife()); loadvideoad(); } }
Comments
Post a Comment