2016-04-28 10 views
1

ゲームを一時停止すると、このビデオの最後にスキップ不可能なビデオをクリックして見ることができるボタンがあります。私は以下を実装したい:結果を表示Unity ADS報酬

動画が最後まで視聴されている場合、余分な心臓1個(最大3個の完全な心臓)が得られ、チャットボックスまたは警告ダイアログが表示されます。

ビデオが開いていない場合、完全に読み込まれたり何かがうまくいかない場合、何も表示されず、チャットボックスまたは警告ダイアログが表示されます。

現在ビデオが読み込まれますが、ビデオが終了すると、賞金は受け取られません(余分な1心)、私のコードで何が間違っていますか?

以下は、現在の心のシステムスクリプトの下

using UnityEngine; 
using System.Collections; 
using UnityEngine.Advertisements; 
using UnityEngine.UI; 

public class Ads : MonoBehaviour { 

    public Button getAds; 
    private Hearts heart; 

    void OnEnable() 
    { 
     getAds.onClick.AddListener (() => GetAds (getAds)); 
    } 


    private void GetAds (Button buttonPressed) 
    { 
     if (buttonPressed == getAds) { 

      Advertisement.Initialize ("XXXXXX", true); 
      Advertisement.IsReady ("rewardedVideo"); 
      Advertisement.Show ("rewardedVideo"); 
      } 
    } 

    public void HandleShowResult (ShowResult result) 
    { 
     switch (result) 
     { 
     case ShowResult.Finished: 
      heart = GameObject.FindGameObjectWithTag ("Hearts").GetComponent<Hearts>() as Hearts; 
      heart.AddHeart(); 
      break; 

     case ShowResult.Skipped: 
      Debug.Log("The ad was skipped before reaching the end."); 
      break; 

     case ShowResult.Failed: 
      Debug.LogError("The ad failed to be shown."); 
      break; 
     } 
    } 


    void OnDisable() 
    { 
     getAds.onClick.RemoveAllListeners(); 
    } 
} 

あなたのコードは、それがなければ

ShowOptions options = new ShowOptions(); 
options.resultCallback = HandleShowResult; 
Advertisement.Show(zoneId, options); 

を最も重要な部分が欠落している

using UnityEngine; 
using System.Collections; 

public class Hearts : MonoBehaviour { 

    public Texture2D[]initialHeart; 
    private int hearts; 
    private int currentHearts; 

    void Start() { 

     GetComponent<GUITexture>().texture = initialHeart[0]; 
     hearts = initialHeart.Length; 

    } 

    void Update() { 

    } 

    public bool TakeHeart() 
    { 
     if (hearts < 0) { 

      return false; 

     } 

     if (currentHearts < (hearts - 1)) { 

      currentHearts += 1; 
      GetComponent<GUITexture>().texture = initialHeart [currentHearts]; 
      return true; 


     } else { 

      return false; 

     } 
    } 

    public bool AddHeart() { 

     if (currentHearts > 0) { 
      currentHearts -= 1; 
      GetComponent<GUITexture>().texture = initialHeart [currentHearts]; 
      return true; 
     } else { 
      return false; 

     } 
    } 
} 
+0

+1です。あなたはあなたの質問を修正し、あなたの質問を言い換える必要があります。今私はそれを読んで混乱してしまった。また、質問は「?」で終わります。 "私のコードに何が間違っていますか?" "なぜ私の広告が表示されないのですか?" ... – Programmer

答えて

1

HandleShowResult文句を言わないボタンの広告です広告が表示された後に何が起こったのか分かりません。また、スコアも増分しません。私はcoroutineを実装し、広告を表示する前にすべてが問題ないことを確認しました。これはテストされていませんが、問題は簡単に修正できます。エラーは赤色で表示されます。緑は成功を意味します。

public class Ads : MonoBehaviour 
{ 

    public string gameId; 
    public string zoneId; 

    public Button getAds; 

    private Hearts heart; 

    void OnEnable() 
    { 
     getAds.onClick.AddListener(() => GetAds(getAds)); 
    } 


    private void GetAds(Button buttonPressed) 
    { 
     if (buttonPressed == getAds) 
     { 
      //Wait for ad to show. The timeout time is 3 seconds 
      StartCoroutine(showAdsWithTimeOut(3)); 
     } 
    } 


    public void HandleShowResult(ShowResult result) 
    { 
     switch (result) 
     { 
      case ShowResult.Finished: 
       heart = GameObject.FindGameObjectWithTag("Hearts").GetComponent<Hearts>() as Hearts; 
       heart.AddHeart(); 
       Debug.Log("<color=green>The ad was skipped before reaching the end.</color>"); 
       break; 

      case ShowResult.Skipped: 
       Debug.Log("<color=yellow>The ad was skipped before reaching the end.</color>"); 
       break; 

      case ShowResult.Failed: 
       Debug.LogError("<color=red>The ad failed to be shown.</color>"); 
       break; 
     } 
    } 

    IEnumerator showAdsWithTimeOut(float timeOut) 
    { 
     //Check if ad is supported on this platform 
     if (!Advertisement.isSupported) 
     { 
      Debug.LogError("<color=red>Ad is NOT supported</color>"); 
      yield break; //Exit coroutine function because ad is not supported 
     } 

     Debug.Log("<color=green>Ad is supported</color>"); 

     //Initialize ad if it has not been initialized 
     if (!Advertisement.isInitialized) 
     { 
      //Initialize ad 
      Advertisement.Initialize(gameId, true); 
     } 


     float counter = 0; 
     bool adIsReady = false; 

     // Wait for timeOut seconds until ad is ready 
     while(counter<timeOut){ 
      counter += Time.deltaTime; 
      if(Advertisement.IsReady (zoneId)){ 
       adIsReady = true; 
       break; //Ad is //Ad is ready, Break while loop and continue program 
      } 
      yield return null; 
     } 

     //Check if ad is not ready after waiting 
     if(!adIsReady){ 
      Debug.LogError("<color=red>Ad failed to be ready in " + timeOut + " seconds. Exited function</color>"); 
      yield break; //Exit coroutine function because ad is not ready 
     } 

     Debug.Log("<color=green>Ad is ready</color>"); 

     //Check if zoneID is empty or null 
     if (string.IsNullOrEmpty(zoneId)) 
     { 
      Debug.Log("<color=red>zoneId is null or empty. Exited function</color>"); 
      yield break; //Exit coroutine function because zoneId null 
     } 

     Debug.Log("<color=green>ZoneId is OK</color>"); 


     //Everything Looks fine. Finally show ad (Missing this part in your code) 
     ShowOptions options = new ShowOptions(); 
     options.resultCallback = HandleShowResult; 

     Advertisement.Show(zoneId, options); 
    } 

    void OnDisable() 
    { 
     getAds.onClick.RemoveAllListeners(); 
    } 
} 
+0

超メガバイクブラスター、101%を実行...私はgameid = "XXXXXXX"とzondeId = "rewardedVideo"あなたの助けと忍耐のために1回。 –

+0

@AlanVieiraRezendeようこそ。私はあなたの他の質問にも答えました。だからそれをチェックしてください.http://stackoverflow.com/questions/36875918/save-sound-value-playerprefers – Programmer

+0

ok私はテストしましょう!すぐにもどる ... –