Search Unity

My rewarded video ads are not showing

Discussion in 'Unity Ads & User Acquisition' started by witcher101, Mar 20, 2017.

  1. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class UnityAdsButton : MonoBehaviour {
    7.     public string zoneId;
    8.     Button m_Button;
    9.     // Use this for initialization
    10.     void Awake()
    11.     {
    12.         Advertisement.Initialize(zoneId, false);
    13.     }
    14.  
    15.     void Start() {
    16.  
    17.         m_Button = GetComponent<Button>();
    18.         if (m_Button) m_Button.onClick.AddListener(ShowAdPlacement);
    19.  
    20.         StartCoroutine(ShowAdWhenReady());
    21.     }
    22.     IEnumerator ShowAdWhenReady()
    23.     {
    24.         while (!Advertisement.IsReady())
    25.             yield return null;
    26.  
    27.         Advertisement.Show();
    28.     }
    29.     // Update is called once per frame
    30.     void Update()
    31.     {
    32.         if (m_Button)
    33.         {
    34.             if (string.IsNullOrEmpty(zoneId)) zoneId = null;
    35.             m_Button.interactable = Advertisement.IsReady(zoneId);
    36.         }
    37.     }
    38.     void ShowAdPlacement()
    39.     {
    40.         if (string.IsNullOrEmpty(zoneId)) zoneId = null;
    41.         var options = new ShowOptions();
    42.         options.resultCallback = HandleShowResult;
    43.         Advertisement.Show(zoneId, options);
    44.     }
    45.  
    46.     void HandleShowResult(ShowResult result)
    47.     {
    48.         switch (result)
    49.         {
    50.             case ShowResult.Finished:
    51.                 Debug.Log("Video completed. Offer a reward to the player.");
    52.                 break;
    53.             case ShowResult.Skipped:
    54.                 Debug.LogWarning("Video was skipped.");
    55.                 break;
    56.             case ShowResult.Failed:
    57.                 Debug.LogError("Video failed to show.");
    58.                 break;
    59.         }
    60.         if (result == ShowResult.Finished)
    61.         {
    62.             m_Button.interactable = false;
    63.             MainGameController.totalMoneyMade *= 2;
    64.  
    65.         }
    66.     }
    67. }
    68.  
    I am trying to show rewarded videos, it doesnt show up. I used test ads 1st. 1 ad is shown at start of game.
    But rewarded video button remains uninteractable. Then i put test ads to false and still no ads are shown not even the 1st ad when game starts. What am i doing wrong??
     
  2. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    "Advertisement.Initialize(zoneId, false);"

    You should initialize with a game id, not zone id.
     
  3. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    ya i am initialising with gameid from unity dashbaord.
    its just named zoneid in code
     
  4. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    But later in your code, you also use zoneId for Show() method. Concepts:

    Game id: The integer number, which you get from dashboard, e.g. 1000000. This is used for Initialize() call
    Placement id: The "placement" in your game, which can be configured from dashboard. Default placements are typically "video" and "rewardedVideo". This is used for IsReady() and Show() calls

    Seems you have copied most of your code from https://unity3d.com/services/ads/quick-start-guide. But you should make sure to distinguish between gameId and placementId/zoneId.

    /Rasmus