Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice
Dismiss Notice
Get paid on mobile. As a mobile developer, get started with In-App Purchases and Ads on our new solution page! Check it out here.

My rewarded video ads are not showing

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

  1. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    275
    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

    Unity Technologies

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

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

    witcher101

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

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    851
    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