var _rewarded_ad : RewardedAd
var on_user_earned_reward_listener := OnUserEarnedRewardListener.new()
func _ready():
on_user_earned_reward_listener.on_user_earned_reward = func(rewarded_item : RewardedItem):
# ここに報酬のコードを書く
# _on_load_pressedを読んで広告を開始する
func _on_load_pressed():
if _rewarded_ad:
_rewarded_ad.destroy()
_rewarded_ad = null
var unit_id : String
if OS.get_name() == "Android":
unit_id = "ca-app-pub-XXXXXXXXXX/XXXXXXXXXX"
elif OS.get_name() == "iOS":
unit_id = "ca-app-pub-XXXXXXXXXX/XXXXXXXXXX"
var rewarded_ad_load_callback := RewardedAdLoadCallback.new()
rewarded_ad_load_callback.on_ad_failed_to_load = func(adError : LoadAdError) -> void:
print(adError.message)
rewarded_ad_load_callback.on_ad_loaded = func(rewarded_ad : RewardedAd) -> void:
print("rewarded ad loaded" + str(rewarded_ad._uid))
_rewarded_ad = rewarded_ad
_rewarded_ad.show(on_user_earned_reward_listener)
RewardedAdLoader.new().load(unit_id, AdRequest.new(), rewarded_ad_load_callback)