为什么插页式广告不起作用?

时间:2018-06-09 16:48:55

标签: unity3d

Unity 2d游戏设施

当GameOver出现在我身上时,我想在我的Unity游戏中放置广告。

没有错误,但它不起作用。

不幸的是,插页式广告并不起作用。有什么帮助吗?

我也尝试从另一个脚本调用GameOver函数,但不幸的是它没有帮助

我试图以多种方式解决问题。

我看了很多教程,视频和指南,但没有任何作用。

我真的处于巨大的沮丧中。

我一直试图解决这个问题11天。

 public class Gamer : MonoBehaviour {

 [SerializeField]
 Camera camMain;
 int index =1;
 public GameObject ImageOver, restartButton , menuButton;
 public GameObject WinSystem;
 public GameObject Manager;
 public AudioClip destroySound;
 private InterstitialAd interstitial;
 void Awake ()
 {
     WinSystem.SetActive (false);
 }
 void Start ()
 {
     RequestInterstitial() ;
     GetComponent<AudioSource> ().playOnAwake = false;
     GetComponent<AudioSource> ().clip = destroySound;
 }

 public void OnCollisionEnter2D (Collision2D col)
 {

     collisionObject colObj= col.transform.GetComponent<collisionObject>();
     if(!colObj) return;
     CheckDestroyedIndex(colObj);
 }

 void CheckDestroyedIndex(collisionObject cObj) {
     if(index == cObj.myIndexNumber)
     {
         if (cObj.isHighestNumber)
         {
             Debug.Log ("Yay you correctly hit the last Square, You WIN!");
             WinSystem.SetActive (true);
             gameObject.SetActive (false);
             Manager.SetActive (false);
         }

         Destroy(cObj.gameObject);
         index++;
     }

     // here, we know it didn't match the number. :)
     else
     {
         GameOver ();
         {
             if (interstitial.IsLoaded()) {
                 interstitial.Show();
             }
         }
     }
 }

 void GameOver (){
     ImageOver.SetActive (true);
     restartButton.SetActive (true);
     menuButton.SetActive (true);
     gameObject.SetActive (false);
     Manager.SetActive (false);
     WinSystem.SetActive (false);
 }

 void Update() {
     if(Input.GetMouseButtonDown(0)) {
         RaycastHit2D hit = Physics2D.Raycast(camMain.ScreenToWorldPoint(Input.mousePosition), Vector3.zero);
         if(hit) {
             collisionObject cObj = hit.collider.GetComponent<collisionObject>();
             if(cObj) {
                 AudioSource.PlayClipAtPoint(destroySound, Camera.main.transform.position);
                 CheckDestroyedIndex(cObj);
             }
         }
     }
 }

 private void RequestInterstitial()
 {
     #if UNITY_ANDROID
     string adUnitId = "ca-app-pub-3940256099942544/1033173712";
     #elif UNITY_IPHONE
     string adUnitId = "ca-app-pub-3940256099942544/4411468910";
     #else
     string adUnitId = "unexpected_platform";
     #endif
     // Clean up interstitial ad before creating a new one.
     if (this.interstitial != null) {
         this.interstitial.Destroy ();
     }

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


     // Called when an ad request has successfully loaded.
     interstitial.OnAdLoaded += HandleOnAdLoaded;
     // Called when an ad request failed to load.
     interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad;
     // Called when an ad is shown.
     interstitial.OnAdOpening += HandleOnAdOpened;
     // Called when the ad is closed.
     interstitial.OnAdClosed += HandleOnAdClosed;
     }

     public void HandleOnAdLoaded(object sender, EventArgs args)
     {
     MonoBehaviour.print("HandleAdLoaded event received");
     }
     public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
     {
     MonoBehaviour.print("HandleFailedToReceiveAd event received with message: "
     + args.Message);
     }
     public void HandleOnAdOpened(object sender, EventArgs args)
     {
     MonoBehaviour.print("HandleAdOpened event received");
     }
     public void HandleOnAdClosed(object sender, EventArgs args)
     {
     MonoBehaviour.print("HandleAdClosed event received");
     }
     }

0 个答案:

没有答案
相关问题