Problem with AdButton

I’m trying to create a system that recharge an X number of lives when the Player watch an entire ad. However the ShowResult.Finished event is never called.

Sorry for my bad english.

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

public class AdReward : MonoBehaviour
{
    [SerializeField] private float CD = 1;
    [SerializeField] private int recharges = 5;
    [SerializeField] private int maxLifes = 15;
    [SerializeField] private string gameID = "53863";
    [SerializeField] private string zoneID = "energyRewardedVideo";


    private int lifes;
    private double counter;
    private bool showAD = false;
    private bool loaded = false;

    private Button reloadButton;
    private Text buttonText;
    private ShowOptions options;
    private DateTime lastReloadDate;


    void Awake()
    {
        Advertisement.Initialize (gameID);
    }
   
    void Start()
    {

        lastReloadDate = DateTime.Parse (PlayerPrefs.GetString ("lastReloadDate", DateTime.Now.ToString ()));
        if (!PlayerPrefs.HasKey ("lastReloadDate"))
            PlayerPrefs.SetString ("lastReloadDate", lastReloadDate.ToString ());
       

        reloadButton = GetComponent<Button> ();
        buttonText = GetComponentInChildren<Text> ();


        lifes = PlayerPrefs.GetInt ("lifes");
       
       
       
    }
   
    void Update()
    {

        counter = (DateTime.Now - lastReloadDate).TotalMinutes;
       

        if(counter >= CD)
        {

            if(!showAD)
            {
                buttonText.text = "Hold On";

                if(!loaded)
                {
                    LoadAd();
                    loaded = true;
                }
            }

            else
            {
                buttonText.text = "Click to Reload";
                reloadButton.onClick.AddListener(() => { OnButtonDown();  });
            }
        }

        else
        {
            buttonText.text = (int)(CD - (int)counter) + "m left";
            reloadButton.onClick.RemoveAllListeners();
        }
       

    }

    void OnButtonDown()
    {
        Advertisement.Show (zoneID, options);
        lastReloadDate = DateTime.Now;
        PlayerPrefs.SetString ("lastReloadDate", lastReloadDate.ToString ());// salva o tempo
        showAD = false;
        loaded = false;
       
    }
   

    void LoadAd()
    {
        StartCoroutine (LoadEvent ());
    }
   
    IEnumerator LoadEvent()
    {
        options = new ShowOptions ();
        options.resultCallback = CallBackhandler;
       
       
        while(!Advertisement.IsReady(zoneID))
            yield return null;


        showAD = true;
    }
   
   
    void CallBackhandler(ShowResult result)
    {
        if (result == ShowResult.Finished)
        {
            RewardPlayer();
            Application.LoadLevel (Application.loadedLevel);
        }
        if(result == ShowResult.Skipped)
        {

            Debug.Log("Skipped");
        }
        if (result == ShowResult.Failed)
        {

            Debug.Log("Fail");
        }
       
    }
   
    void RewardPlayer()
    {
        Debug.Log ("Finished");
        lifes += recharges;
        if (lifes > maxLifes)
            lifes = maxLifes;
        PlayerPrefs.SetInt ("lifes", lifes);
    }
}

Are you sure the LoadEvent() method is called before calling Show()? Your code seems a little complex to me, e.g. why are you setting button eventhandler on Update (e.g. every frame), and why are the options instantiated elsewhere from where used?

Think you should generally clean up your code, and instantiate the ShowOptions object right before your call to Show(), as it’s not being used for anything else, so cleaner just to keep it in the same scope, as where it’s being used.

Hope this helps.

/Rasmus

First thanks for your help.

When I’m in the editor the script works