2017-02-26 30 views

答えて

2

テストが、動作するはずはない:

EDIT:編集した部分は、Googleのチュートリアルから文字通りです。 Googleを時々行うと、多くのことを学びます。

using System; 
using UnityEngine; 
using GoogleMobileAds.Api; 

public class AdMobOnPause : MonoBehaviour 
{ 
    public string AndroidInterstitialID = "INSERT_ANDROID_INTERSTITIAL_AD_UNIT_ID_HERE"; 
public string IOSInterstitialID = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE"; 


private static AdMobOnPause instance; 

private InterstitialAd interstitial; 
// ADD THIS 
private RewardBasedVideoAd rewardBasedVideo; 

private AdRequest request; 
void Awake() 
{ 
    if (AdMobOnPause.instance != null) 
    { 
     Destroy(gameObject); //just allow one adscontroller on scene over gameplay, even when you restart this level 
    } 
} 
void Start() 
{ 
    DontDestroyOnLoad(gameObject); 
    instance = this; 
    RequestInterstitial(); 
    //Request Video! 
    RequestRewardBasedVideo(); 
} 

//ADD THESE TWO METHODS 
void OnEnable() { 
rewardBasedVideo.OnAdRewarded += HandleRewardedSuccessful; 
} 

void OnDisable() { 
rewardBasedVideo.OnAdRewarded -= HandleRewardedSuccessful; 
} 

private void RequestInterstitial() 
{ 
#if UNITY_ANDROID 
    string adUnitId = AndroidInterstitialID; 
#elif UNITY_IPHONE 
    string adUnitId = IOSInterstitialID; 
#else 
    string adUnitId = "unexpected_platform"; 
#endif 

    // Initialize an InterstitialAd. 
    interstitial = new InterstitialAd(adUnitId); 
    interstitial.OnAdClosed += HandleEventHandler; 
    // Create an empty ad request. 
    request = new AdRequest.Builder().Build(); 
    // Load the interstitial with the request. 
    interstitial.LoadAd(request); 
} 

void HandleEventHandler(object sender, System.EventArgs e) 
{ 
    interstitial.Destroy(); 
    interstitial.LoadAd(request); 
} 

public void Pause() 
{ 
    //your pause code here or, 
    //if(Time.timeScale < 1) 
    // Time.timeScale = 1; 
    //else 
    // Time.timeScale = 0; 
    if (interstitial.IsLoaded()) 
    { 
     interstitial.Show(); 
    } 
} 
//From here on is the Rewarded video code. 
private void RequestRewardBasedVideo() 
{ 
#if UNITY_ANDROID 
    string adUnitId = "INSERT_AD_UNIT_HERE"; 
#elif UNITY_IPHONE 
    string adUnitId = "INSERT_AD_UNIT_HERE"; 
#else 
    string adUnitId = "unexpected_platform"; 
#endif 

    rewardBasedVideo = RewardBasedVideoAd.Instance; 

    AdRequest request = new AdRequest.Builder().Build(); 
    rewardBasedVideo.LoadAd(request, adUnitId); 
} 

public void GameOver() 
{ 
    if (rewardBasedVideo.IsLoaded()) 
    { 
     rewardBasedVideo.Show(); 
    } 
} 

public void HandleRewardedSuccessful() { 
// Do Something when rewarded video is successfully watched 
} 

}

+0

おかげで、それが動作しますが、私はまた、報酬ベースのビデオ広告用のC#スクリプトを必要とします。 –

+0

申し訳ありませんがすぐに編集中です – Kokolo

+0

私はそれを解決して心配しないでください –

関連する問題