Search Unity

Difficulty with Reward Ads example

Discussion in 'Unity Ads & User Acquisition' started by theunsigned, Apr 9, 2019.

  1. theunsigned

    theunsigned

    Joined:
    Nov 15, 2018
    Posts:
    33
    I'm trying to follow the Unity Ads Quick Start Guide to incorporate reward ads into my game. Basically, you click a UI button and it gives the player an extra bit of health. But, when I press play and click the button, nothing happens. I appreciate any assistance. Here is my code:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class showrewardad : MonoBehaviour
    7. {
    8.  
    9.     public void ShowRewardedAd()
    10.     {
    11.         if (Advertisement.IsReady("rewardedVideo"))
    12.         {
    13.             var options = new ShowOptions { resultCallback = HandleShowResult };
    14.             Advertisement.Show("rewardedVideo", options);
    15.         }
    16.     }
    17.  
    18.     private void HandleShowResult(ShowResult result)
    19.     {
    20.         var health = GameObject.FindGameObjectWithTag("Player").GetComponent<Health>();
    21.         switch (result)
    22.         {
    23.             case ShowResult.Finished:
    24.                 Debug.Log("The ad was successfully shown.");
    25.                 health.manageHealth(100);
    26.                 break;
    27.             case ShowResult.Skipped:
    28.                 Debug.Log("The ad was skipped before reaching the end.");
    29.                 break;
    30.             case ShowResult.Failed:
    31.                 Debug.LogError("The ad failed to be shown.");
    32.                 break;
    33.         }
    34.     }
    35. }
     
  2. mikaisomaa

    mikaisomaa

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    365
    Are you initialising ads?

    Advertisement.Initialize(gameID, testMode);
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please show your button click code. Also please provide the Debug.Log output