Proper way of doing the "Watch now and earn 1 gem"?

Hi!
What is the proper way of doing this “Watch now and earn 1 gem”? I have a button that says “Watch video and earn 20 coins”.

Do I just make it show the video when user presses the button? Is there a way to check that the video has been fully watched? What things do I need take into consideration?

Hello,

Use this script (Its made by unity officials). Or search this forum, there is plenty of sample script.

If you look that script there is a part like this,

private void HandleShowResult (ShowResult result)
    {
        switch (result)
        {
        case ShowResult.Finished:
            Debug.Log("The ad was successfully shown.");
            break;
        case ShowResult.Skipped:
            Debug.Log("The ad was skipped before reaching the end.");
            break;
        case ShowResult.Failed:
            Debug.LogError("The ad failed to be shown.");
            break;
        }
    }

You can give gem after (“The ad was successfully shown.”).

Regards,

1 Like

Ok, I see. Thank you very much! I will try that.

1 Like

Hey sorry to open up this thread again but what is the correct way to call HandleShowResults from another function? I’ve taken a look at this script HERE but don’t fully understand it.

resultCallback = result => {
                HandleShowResult(result);
            }

Surely it can’t just be a case of calling the HandleShowResults function as the ad wont have finished playing yet. Or is that the case?

Hello will,
You are in the wright place.
When you use Advertisement.Show(…) method. It returns a “result” message after showing your ad. This message contains information about if user skipped or watch the ad to the end.
So with this message you can handle the situation, you can give reward for finished videos etc.

private void HandleShowResult (ShowResult result)
    {
        switch (result)
        {
        case ShowResult.Finished:
            Debug.Log("The ad was successfully shown.");
// YOUR REWARD CODE HERE like gold+=500;
            break;
        case ShowResult.Skipped:
            Debug.Log("The ad was skipped before reaching the end.");
            break;
        case ShowResult.Failed:
            Debug.LogError("The ad failed to be shown.");
            break;
        }
    }

If its not your problem, it means i dont understand your question.
Regards,

1 Like

Thanks Salazar, so your saying I don’t need to call HandleShowResults at all i just need to have it in the script? This is all of my code currently:

    public void ShowAd()
    {
        Debug.Log ("Show Add");
        if (Advertisement.isReady ()) 
        {
            Advertisement.Show();
   
        }
    }

   public void WatchAdForCur(int curAmount)
    {
        Debug.Log ("Show Add");
        if (Advertisement.isReady ())
        {
            Advertisement.Show();
        }
    }

    private void HandleShowResult (ShowResult result)
    {
        switch (result)
        {
        case ShowResult.Finished:
        //** ADD CODE TO CHECK AD RESULTS AND GIVE PAYMENT IF REQUIERED HERE!!!**
            Debug.Log("The ad was successfully shown.");
            break;
        case ShowResult.Skipped:
            Debug.Log("The ad was skipped before reaching the end.");
            break;
        case ShowResult.Failed:
            Debug.LogError("The ad failed to be shown.");
            break;
        }
    }
public void ShowAd (string zone = null)
    {
            ShowAd_CondensedVersion(zone);
    }
private void ShowAd_CondensedVersion (string zone)
    {
        Advertisement.Show(zone, new ShowOptions {
            // With the pause option set to true, the timeScale and AudioListener
            //  volume for your game is set to 0 while the ad is shown.
            pause = true,
            // The resultCallback is triggered when the ad is closed.
            resultCallback = result => {
                HandleShowResult(result);
            }
        });
    }
private void HandleShowResult (ShowResult result)
    {
        switch (result)
        {
        case ShowResult.Finished:
            Debug.Log("The ad was successfully shown.");
            break;
        case ShowResult.Skipped:
            Debug.Log("The ad was skipped before reaching the end.");
            break;
        case ShowResult.Failed:
            Debug.LogError("The ad failed to be shown.");
            break;
        }
    }

Now you just use ShowAd(“ZoneId”); after advertisement ready where you want to show your ad in your game.

You’re on the right track will_brett. Take a look at the following changes made to your code:

public void ShowAd()
{
    Debug.Log ("Show Ad");
    if (Advertisement.isReady())
    {
        Advertisement.Show();

    }
}

public void WatchAdForCur(int curAmount)
{
    Debug.Log ("Show Rewarded Ad");
    if (Advertisement.isReady("rewardedVideoZone"))
    {
        ShowOptions options = new ShowOptions();
        options.resultCallback = HandleShowResultWithReward;
        options.pause = true;
       
        Advertisement.Show("rewardedVideoZone",options);
    }
}

private void HandleShowResultWithReward (ShowResult result)
{
    switch (result)
    {
    case ShowResult.Finished:
        Debug.Log("The ad was successfully shown.");
        //*** REWARD PLAYER FOR WATCHING VIDEO ***
        break;
    case ShowResult.Skipped:
        Debug.Log("The ad was skipped before reaching the end.");
        break;
    case ShowResult.Failed:
        Debug.LogError("The ad failed to be shown.");
        break;
    }
}
2 Likes

Thanks guys really helpful

Where is “WatchAdForCur(int curAmount)” being referenced? Is this something the unity plugin automatically references, or will we have to reference it ourselves in some way? The code given doesn’t show a clear cut way to tell.

Hi, Sign up on Bulmen and make money from anywhere by completing surveys.There are indeed more ways to earn money , but these are the ones that are most easy to implement. .

Hello,
I am new to Unity Ads.
I have implemented Unity Ads and the interstitial ads work fine on both the editor and device.
However, the video ads do not work.
I always get Video Ad not ready.
Does this happen often or am I supposed to get a video ad everytime or just sometimes.
And if only sometimes, then what is the frequency?
Coz they didn’t show up even after 25 times.

Kindly throw some light on.

public void ShowRewardedAd()
    {
        if (Advertisement.IsReady("rewardedVideoZone")) {
            var options = new ShowOptions{resultCallback = HandleShowResult };
            Advertisement.Show ("rewardedVideoZone", options);
        }
        else {
            ad_videoBtn.transform.GetChild (1).GetComponent<Text> ().text = "No ads available :(";
            Debug.Log ("Video ad not ready");   
        }


    }