Search Unity

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

Discussion in 'Unity Ads & User Acquisition' started by Nadan, Jan 10, 2015.

  1. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    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?

     
  2. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    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,
    Code (CSharp):
    1. private void HandleShowResult (ShowResult result)
    2.     {
    3.         switch (result)
    4.         {
    5.         case ShowResult.Finished:
    6.             Debug.Log("The ad was successfully shown.");
    7.             break;
    8.         case ShowResult.Skipped:
    9.             Debug.Log("The ad was skipped before reaching the end.");
    10.             break;
    11.         case ShowResult.Failed:
    12.             Debug.LogError("The ad failed to be shown.");
    13.             break;
    14.         }
    15.     }
    You can give gem after ("The ad was successfully shown.").

    Regards,
     
    unity-nikkolai likes this.
  3. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Ok, I see. Thank you very much! I will try that.
     
    Salazar likes this.
  4. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    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.

    Code (CSharp):
    1. resultCallback = result => {
    2.                 HandleShowResult(result);
    3.             }
    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?
     
    Last edited: Jan 13, 2015
  5. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    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.
    Code (CSharp):
    1. private void HandleShowResult (ShowResult result)
    2.     {
    3.         switch (result)
    4.         {
    5.         case ShowResult.Finished:
    6.             Debug.Log("The ad was successfully shown.");
    7. // YOUR REWARD CODE HERE like gold+=500;
    8.             break;
    9.         case ShowResult.Skipped:
    10.             Debug.Log("The ad was skipped before reaching the end.");
    11.             break;
    12.         case ShowResult.Failed:
    13.             Debug.LogError("The ad failed to be shown.");
    14.             break;
    15.         }
    16.     }
    If its not your problem, it means i dont understand your question.
    Regards,
     
    unity-nikkolai likes this.
  6. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    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:

    Code (CSharp):
    1.  
    2.     public void ShowAd()
    3.     {
    4.         Debug.Log ("Show Add");
    5.         if (Advertisement.isReady ())
    6.         {
    7.             Advertisement.Show();
    8.    
    9.         }
    10.     }
    11.  
    12.    public void WatchAdForCur(int curAmount)
    13.     {
    14.         Debug.Log ("Show Add");
    15.         if (Advertisement.isReady ())
    16.         {
    17.             Advertisement.Show();
    18.         }
    19.     }
    20.  
    21.     private void HandleShowResult (ShowResult result)
    22.     {
    23.         switch (result)
    24.         {
    25.         case ShowResult.Finished:
    26.         //** ADD CODE TO CHECK AD RESULTS AND GIVE PAYMENT IF REQUIERED HERE!!!**
    27.             Debug.Log("The ad was successfully shown.");
    28.             break;
    29.         case ShowResult.Skipped:
    30.             Debug.Log("The ad was skipped before reaching the end.");
    31.             break;
    32.         case ShowResult.Failed:
    33.             Debug.LogError("The ad failed to be shown.");
    34.             break;
    35.         }
    36.     }
     
  7. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Code (CSharp):
    1. public void ShowAd (string zone = null)
    2.     {
    3.             ShowAd_CondensedVersion(zone);
    4.     }
    5. private void ShowAd_CondensedVersion (string zone)
    6.     {
    7.         Advertisement.Show(zone, new ShowOptions {
    8.             // With the pause option set to true, the timeScale and AudioListener
    9.             //  volume for your game is set to 0 while the ad is shown.
    10.             pause = true,
    11.             // The resultCallback is triggered when the ad is closed.
    12.             resultCallback = result => {
    13.                 HandleShowResult(result);
    14.             }
    15.         });
    16.     }
    17. private void HandleShowResult (ShowResult result)
    18.     {
    19.         switch (result)
    20.         {
    21.         case ShowResult.Finished:
    22.             Debug.Log("The ad was successfully shown.");
    23.             break;
    24.         case ShowResult.Skipped:
    25.             Debug.Log("The ad was skipped before reaching the end.");
    26.             break;
    27.         case ShowResult.Failed:
    28.             Debug.LogError("The ad failed to be shown.");
    29.             break;
    30.         }
    31.     }
    Now you just use ShowAd("ZoneId"); after advertisement ready where you want to show your ad in your game.
     
  8. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    You're on the right track will_brett. Take a look at the following changes made to your code:
    Code (CSharp):
    1. public void ShowAd()
    2. {
    3.     Debug.Log ("Show Ad");
    4.     if (Advertisement.isReady())
    5.     {
    6.         Advertisement.Show();
    7.  
    8.     }
    9. }
    10.  
    11. public void WatchAdForCur(int curAmount)
    12. {
    13.     Debug.Log ("Show Rewarded Ad");
    14.     if (Advertisement.isReady("rewardedVideoZone"))
    15.     {
    16.         ShowOptions options = new ShowOptions();
    17.         options.resultCallback = HandleShowResultWithReward;
    18.         options.pause = true;
    19.        
    20.         Advertisement.Show("rewardedVideoZone",options);
    21.     }
    22. }
    23.  
    24. private void HandleShowResultWithReward (ShowResult result)
    25. {
    26.     switch (result)
    27.     {
    28.     case ShowResult.Finished:
    29.         Debug.Log("The ad was successfully shown.");
    30.         //*** REWARD PLAYER FOR WATCHING VIDEO ***
    31.         break;
    32.     case ShowResult.Skipped:
    33.         Debug.Log("The ad was skipped before reaching the end.");
    34.         break;
    35.     case ShowResult.Failed:
    36.         Debug.LogError("The ad failed to be shown.");
    37.         break;
    38.     }
    39. }
     
    will_brett and Salazar like this.
  9. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    Thanks guys really helpful
     
  10. Tekksin

    Tekksin

    Joined:
    Oct 20, 2013
    Posts:
    32

    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.
     
  11. AakritiBasu

    AakritiBasu

    Joined:
    Jan 27, 2016
    Posts:
    1
    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. .
     
  12. Raghav-Arora

    Raghav-Arora

    Joined:
    Feb 22, 2016
    Posts:
    2
    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.

    Code (CSharp):
    1. public void ShowRewardedAd()
    2.     {
    3.         if (Advertisement.IsReady("rewardedVideoZone")) {
    4.             var options = new ShowOptions{resultCallback = HandleShowResult };
    5.             Advertisement.Show ("rewardedVideoZone", options);
    6.         }
    7.         else {
    8.             ad_videoBtn.transform.GetChild (1).GetComponent<Text> ().text = "No ads available :(";
    9.             Debug.Log ("Video ad not ready");  
    10.         }
    11.  
    12.  
    13.     }
    14.