2017-10-25 9 views
1

私は私のゲームでRewardAdを望んでいません。ビデオを見ると、あなたの現在の得点に+10点が得られ、ハイスコアにはなりません。ユニティRewardAd関数呼び出しより多くの時間は、一回だけ

あなたは45ハイスコアを持っているとあなたは今37であるので、あなたは、10のスコアのためにビデオを見て、あなたはそれがいいのよ47ハイスコアを持っています。しかし、あなたがそれをやり直すと、ビデオはあなたに+20のスコアを与えますか?そして次の時間+30など。

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using GoogleMobileAds.Api; 
using System.Threading; 

public class RewardAd : MonoBehaviour { 

    public int highscore; 
    public int score; 
    public static GameObject drawscore_obj; 
    public RewardBasedVideoAd rewardBasedVideo = null; 
    public string adUnitId; 

    void Start() 
    { 
     rewardBasedVideo = null; 
     GetComponent<SpriteRenderer>().enabled = false; 
     //highscore = PlayerPrefs.GetInt ("highscore"); 
     adUnitId = "ca-app-pub-2879768424205988/1590886374"; 
     rewardBasedVideo = RewardBasedVideoAd.Instance; 
     AdRequest request = new AdRequest.Builder().Build(); 
     rewardBasedVideo.LoadAd(request, adUnitId); 
     rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded; 
    } 
    void Update() 
    { 
     if (GameOverScript.GameOver) 
     { 
      GetComponent<SpriteRenderer>().enabled = true; 
     } 
    } 

    void OnMouseDown() 
    { 
     showAdd(rewardBasedVideo); 
    } 

    private void showAdd(RewardBasedVideoAd rewardBasedVideo) 
    { 
     if (rewardBasedVideo.IsLoaded()) 
     { 
      if (GameOverScript.GameOver) 
      { 
       rewardBasedVideo.Show(); 
      } 
     } 
    } 

    public void HandleRewardBasedVideoRewarded(object sender, Reward args) 
    { 
     highscore = PlayerPrefs.GetInt ("highscore"); 

     if ((Controll.points + 10) > highscore) 
     { 
      Controll.points += 10; 
      if(Controll.points > highscore) 
      { 
       PlayerPrefs.SetInt ("highscore", highscore); 
      } 
     } 
    } 
} 
+0

ようこそ!あなたは方法は二回、またはそれが一度と呼ばれるが、20ポイントを追加さ​​れていた場合に呼び出されているかどうかを説明することができればあなたの質問は、より明確になります。広告が表示されるたびにイベントを追加しますが、削除することはないため、そのように見えます。 – DSway

+0

ありがとう! :)私の悪い英語のためにSry ...私は2回呼ばれ、10 + 10ポイントを追加する方法を言ってみたいです。私はDebug.Logでメソッド呼び出しをチェックしました! :) – antal1208

答えて

1

あなたは、このメソッドを見れば:

private void showAdd(RewardBasedVideoAd rewardBasedVideo) 
{ 
    if (rewardBasedVideo.IsLoaded()) 
    { 
     if (GameOverScript.GameOver) 
     { 
      rewardBasedVideo.Show(); 
      rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded; 
     } 
    } 
} 

それが呼ばれていますたびに、それはOnAdRewardedHandleRewardBasedVideoRewardedの別のリスナーを追加します。だから、初めてHandleRewardBasedVideoRewardedと呼ぶでしょう。 2度目の2回目。等々。

通常は、あなたが一度だけリスナーを追加します。私は私の問題を解決し

void Start() 
{ 
    rewardBasedVideo = null; 
    GetComponent<SpriteRenderer>().enabled = false; 
    //highscore = PlayerPrefs.GetInt ("highscore"); 
    adUnitId = "ca-app-pub-2**97684242*****/15*08*****"; 
    rewardBasedVideo = RewardBasedVideoAd.Instance; 
    AdRequest request = new AdRequest.Builder().Build(); 
    rewardBasedVideo.LoadAd(request, adUnitId); 

    // Add a listener only when the script is loaded 
    rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded; 
} 

private void showAdd(RewardBasedVideoAd rewardBasedVideo) 
{ 
    if (rewardBasedVideo.IsLoaded()) 
    { 
     if (GameOverScript.GameOver) 
     { 
      rewardBasedVideo.Show(); 
     } 
    } 
} 
+0

answareありがとう!私は私が20ポイントを得るビデオを見るときにメソッドを最初に起動するには、この行を追加すると...次回は私が手40>< – antal1208

+0

@ antal1208あなたが他を削除しました 'rewardBasedVideo.OnAdRewarded + = HandleRewardBasedVideoRewarded;'から ' showAdd'? –

+0

ええ、私は削除! – antal1208

0

!私はちょっとしたノブがその仕事に噛み合っていると思う:D

using System.Collections; 
    using System.Collections.Generic; 
    using UnityEngine; 
    using GoogleMobileAds.Api; 
    using System.Threading; 

    public class RewardAd : MonoBehaviour { 

     public bool called; 
     public int highscore; 
     public int score; 
     public static GameObject drawscore_obj; 
     public RewardBasedVideoAd rewardBasedVideo = null; 
     public string adUnitId; 

     void Start() 
     { 
      called = false; 
      rewardBasedVideo = null; 
      GetComponent<SpriteRenderer>().enabled = false; 
      //highscore = PlayerPrefs.GetInt ("highscore"); 
      adUnitId = "ca-app-pub-2879768424205988/1590886374"; 
      rewardBasedVideo = RewardBasedVideoAd.Instance; 
      AdRequest request = new AdRequest.Builder().Build(); 
      rewardBasedVideo.LoadAd(request, adUnitId); 
      rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded; 
     } 
     void Update() 
     { 
      if (GameOverScript.GameOver) 
      { 
       GetComponent<SpriteRenderer>().enabled = true; 
      } 
     } 

     void OnMouseDown() 
     { 
      showAdd(rewardBasedVideo); 
     } 

     private void showAdd(RewardBasedVideoAd rewardBasedVideo) 
     { 
      if (rewardBasedVideo.IsLoaded()) 
      { 
       if (GameOverScript.GameOver) 
       { 
        rewardBasedVideo.Show(); 
        called = true; 
       } 
      } 
     } 

     public void HandleRewardBasedVideoRewarded(object sender, Reward args) 
     { 
      if (called == true) 
      { 
       called = false; 
       highscore = PlayerPrefs.GetInt ("highscore"); 

       if ((Controll.points + 10) > highscore) { 
        Controll.points += 10; 
        if (Controll.points > highscore) { 
         PlayerPrefs.SetInt ("highscore", highscore); 
        } 
       } 
      } 
     } 
     } 
関連する問題