# Problem with AdButton

**URL:** https://discussions.unity.com/t/problem-with-adbutton/592418
**Category:** Unity Ads
**Tags:** Unity-Ads-and-User-Acquisition
**Created:** [August 5, 2015, 10:22pm UTC](https://discussions.unity.com/t/problem-with-adbutton/592418 "2015-08-05T22:22:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Pedro\_Luckas](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/pedro_luckas/32/441923_2.png) [@Pedro\_Luckas](https://discussions.unity.com/u/Pedro_Luckas)
#### Post date: [August 5, 2015, 10:22pm UTC](https://discussions.unity.com/t/problem-with-adbutton/592418/1 "2015-08-05T22:22:32Z")

</div>

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.

```csharp
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);
    }
}

```

---

<div class="post-metadata">

### Author: ![rasmus-unity](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rasmus-unity](https://discussions.unity.com/u/rasmus-unity)
#### Post date: [August 6, 2015, 6:18am UTC](https://discussions.unity.com/t/problem-with-adbutton/592418/2 "2015-08-06T06:18:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Pedro\_Luckas](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/pedro_luckas/32/441923_2.png) [@Pedro\_Luckas](https://discussions.unity.com/u/Pedro_Luckas)
#### Post date: [August 6, 2015, 5:50pm UTC](https://discussions.unity.com/t/problem-with-adbutton/592418/3 "2015-08-06T17:50:08Z")

</div>

First thanks for your help.

When I’m in the editor the script works
