リワード広告を実装しようとすると次のようなエラーが出てしまい、実行ができません。どのようにスクリプトを書けばエラーが出ないようになりますか?
エラー
Assets/Scripts/Reward.cs(28,9): error CS0123: デリゲート 'EventHandler<AdFailedToLoadEventArgs>' に一致する 'HandleRewardedAdFailedToLoad' のオーバーロードはありません
書いたスクリプト
C#
1using UnityEngine.Events; 2using UnityEngine; 3using GoogleMobileAds.Api; 4using GoogleMobileAds.Common; 5using UnityEngine.UI; 6using System; 7using System.Collections.Generic; 8 9public class Reward : MonoBehaviour 10{ 11 private RewardedAd rewardedAd; 12 13 public void Start() 14 { 15 string adUnitId; 16#if UNITY_ANDROID 17 adUnitId = "ca-app-pub-3940256099942544/5224354917"; 18#elif UNITY_IPHONE 19 adUnitId = "ca-app-pub-3940256099942544/1712485313"; 20#else 21 adUnitId = "unexpected_platform"; 22#endif 23 this.rewardedAd = new RewardedAd(adUnitId); 24 25 // Called when an ad request has successfully loaded. 26 this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded; 27 28 //28行目 29 // Called when an ad request failed to load. 30 this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad; 31 32 // Called when an ad is shown. 33 this.rewardedAd.OnAdOpening += HandleRewardedAdOpening; 34 // Called when an ad request failed to show. 35 this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow; 36 // Called when the user should be rewarded for interacting with the ad. 37 this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward; 38 // Called when the ad is closed. 39 this.rewardedAd.OnAdClosed += HandleRewardedAdClosed; 40 41 // Create an empty ad request. 42 AdRequest request = new AdRequest.Builder().Build(); 43 // Load the rewarded ad with the request. 44 this.rewardedAd.LoadAd(request); 45 } 46 47 public void HandleRewardedAdLoaded(object sender, EventArgs args) 48 { 49 MonoBehaviour.print("HandleRewardedAdLoaded event received"); 50 } 51 52 public void HandleRewardedAdFailedToLoad(object sender, AdErrorEventArgs args) 53 { 54 MonoBehaviour.print( 55 "HandleRewardedAdFailedToLoad event received with message: " 56 + args.Message); 57 } 58 59 public void HandleRewardedAdOpening(object sender, EventArgs args) 60 { 61 MonoBehaviour.print("HandleRewardedAdOpening event received"); 62 } 63 64 public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args) 65 { 66 MonoBehaviour.print( 67 "HandleRewardedAdFailedToShow event received with message: " 68 + args.Message); 69 } 70 71 public void HandleRewardedAdClosed(object sender, EventArgs args) 72 { 73 MonoBehaviour.print("HandleRewardedAdClosed event received"); 74 } 75 76 public void HandleUserEarnedReward(object sender, Reward args) 77 { 78 string type = args.Type; 79 double amount = args.Amount; 80 MonoBehaviour.print( 81 "HandleRewardedAdRewarded event received for " 82 + amount.ToString() + " " + type); 83 } 84}
追記
32行目にも同じようなエラーが出てしまいました。どのような引数の型を書けばエラーが発生されなくなりますか?
エラー
Assets/Scripts/Reward1.cs(32,9): error CS0123: デリゲート 'EventHandler<AdErrorEventArgs>' に一致する 'HandleRewardedAdFailedToShow' のオーバーロードはありません
スクリプト
C#
1using UnityEngine.Events; 2using UnityEngine; 3using GoogleMobileAds.Api; 4using GoogleMobileAds.Common; 5using UnityEngine.UI; 6using System; 7using System.Collections.Generic; 8 9public class Reward1 : MonoBehaviour 10{ 11 private RewardedAd rewardedAd; 12 13 public void Start() 14 { 15 string adUnitId; 16#if UNITY_ANDROID 17 adUnitId = "ca-app-pub-3940256099942544/5224354917"; 18#elif UNITY_IPHONE 19 adUnitId = "ca-app-pub-3940256099942544/1712485313"; 20#else 21 adUnitId = "unexpected_platform"; 22#endif 23 this.rewardedAd = new RewardedAd(adUnitId); 24 25 // Called when an ad request has successfully loaded. 26 this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded; 27 // Called when an ad request failed to load. 28 this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad; 29 // Called when an ad is shown. 30 this.rewardedAd.OnAdOpening += HandleRewardedAdOpening; 31 // Called when an ad request failed to show. 32 this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;//32行目 33 // Called when the user should be rewarded for interacting with the ad. 34 this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward; 35 // Called when the ad is closed. 36 this.rewardedAd.OnAdClosed += HandleRewardedAdClosed; 37 38 // Create an empty ad request. 39 AdRequest request = new AdRequest.Builder().Build(); 40 // Load the rewarded ad with the request. 41 this.rewardedAd.LoadAd(request); 42 } 43 44 public void HandleRewardedAdLoaded(object sender, EventArgs args) 45 { 46 MonoBehaviour.print("HandleRewardedAdLoaded event received"); 47 } 48 //AdErrorEventArgs 49 //AdFailedToLoadEventArgs 50 public void HandleRewardedAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) 51 { 52 MonoBehaviour.print( 53 "HandleRewardedAdFailedToLoad event received with message: " 54 + args.Message); 55 } 56 57 public void HandleRewardedAdOpening(object sender, EventArgs args) 58 { 59 MonoBehaviour.print("HandleRewardedAdOpening event received"); 60 } 61 62 public void HandleRewardedAdFailedToShow(object sender, AdFailedToLoadEventArgs args) 63 { 64 MonoBehaviour.print( 65 "HandleRewardedAdFailedToShow event received with message: " 66 + args.Message); 67 } 68 69 public void HandleRewardedAdClosed(object sender, EventArgs args) 70 { 71 MonoBehaviour.print("HandleRewardedAdClosed event received"); 72 } 73 74 public void HandleUserEarnedReward(object sender, Reward args) 75 { 76 string type = args.Type; 77 double amount = args.Amount; 78 MonoBehaviour.print( 79 "HandleRewardedAdRewarded event received for " 80 + amount.ToString() + " " + type); 81 } 82}
試したこと
・プラグインを最新バージョンにしてインポートした ・unityを再起動した ・HandleRewardedAdFailedToShowの引数の型をAdFailedToLoadEventArgsにもしてみましたがエラーが出ました
あなたの回答
tips
プレビュー