Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Question concerning Video adds return value

Discussion in 'Unity Ads' started by Fluzing, Nov 13, 2014.

  1. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    I am currently testing video ads in my game. I have made a level unlock system where people can watch video's to unlock levels. When I build the game, the video's work perfectly, but it seems it returns the wrong value when they finish. Is this due to the fact that my account is still in test mode or is my code incorrect?

    Code (csharp):
    1.  
    2.     public int ShowVideo()
    3.     {
    4.         ShowResult result_x = 0;  
    5.         Advertisement.Show("rewardedVideoZone", new ShowOptions {
    6.                 pause = true,
    7.                 resultCallback = result => {
    8.                         result_x = result;//0 = fail, 1 = skipped, 2 = finished
    9.                 }
    10.             });
    11.         return (int)result_x;
    12.     }
    13.  
    I am using the int from result to determine if the video was completed or not.
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Noone?
     
  3. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    236
    Hello,
    A little information, I am not sure but , in test mode when you show a video ad, It always return finished.

    I am sending my code, it works with my game with no problem,

    Code (CSharp):
    1. public void PlayVideo(bool canplayvideo)
    2.     {
    3.         if(canplayvideo)
    4.         {
    5.             canplayvideo=false;
    6.             Advertisement.Show(@"defaultVideoAndPictureZone", new ShowOptions {
    7.                 pause = false,
    8.             // Handle the various result callback states.
    9.             resultCallback = result => {
    10.                 switch (result)
    11.                 {
    12.                 case ShowResult.Finished:
    13.  
    14.                        ///Your code if it viewed
    15.                     break;
    16.                 case ShowResult.Skipped:
    17.                        ///Your code if it skipped
    18.                     break;
    19.                 case ShowResult.Failed:
    20.                        ///Your code if it fails
    21.                     break;
    22.                 }
    23.             }
    24.         });
    25.     }
    I take this code from this forum.
     
    unity-nikkolai likes this.
  4. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Thanks, that did it for me.
     
    unity-nikkolai and Salazar like this.
  5. MadMapp

    MadMapp

    Joined:
    Nov 15, 2012
    Posts:
    49
    this is the correct way to perform a rewardable video advert correct? struggling to find an example, but this is it right?
     
  6. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    This worked for me.
     
  7. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Here is another example (copied from UnityAdsHelper.cs):

    Code (CSharp):
    1. public static void ShowAd (string zone = null, bool pauseGameDuringAd = true)
    2. {
    3.     if (string.IsNullOrEmpty(zone)) zone = null;
    4.  
    5.     ShowOptions options = new ShowOptions();
    6.     options.pause = pauseGameDuringAd;
    7.     options.resultCallback = HandleShowResult;
    8.    
    9.     Advertisement.Show(zone,options);
    10. }
    11.    
    12. public static void HandleShowResult (ShowResult result)
    13. {
    14.     switch (result)
    15.     {
    16.     case ShowResult.Finished:
    17.         Debug.Log("The ad was successfully shown.");
    18.         break;
    19.     case ShowResult.Skipped:
    20.         Debug.Log("The ad was skipped before reaching the end.");
    21.         break;
    22.     case ShowResult.Failed:
    23.         Debug.LogError("The ad failed to be shown.");
    24.         break;
    25.     }
    26. }
    You can check out and download the full demo project here. Feel free to use any part of it and customize the scripts for your own needs. You're welcome to reach out to me with any questions you might have.
     
    Salazar likes this.
  8. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    77
    Sorry to bump an old thread, but I have a question about ShowResult.Failed and need some advice on the best way to handle rewarded ads.

    For the iOS game I'm writing, I'm intending that users playing the free version of the game will need to watch ads to progress through the level campaign or to perform certain other actions, and this is likely to be the major proportion of my revenue. I can see that .Finished and .Skipped give reasonable feedback about whether the user met the criteria from a user action point of view. However, I am not clear on what are the reasons why .Failed might appear?

    Is this caused mostly due to lack of internet connection, or an ad blocker, preventing the ads from caching? Are there other legitimate reasons why an ad might fail to show? I am somewhat torn here about how should I best design the progression so that (1) If I treat .Failed as a reward pass, then how can I ensure that users can't abuse the system by simply blocking ads or turning off their network; and (2) If I treat the .Failed as a reward skip then how do I avoid penalising users who might not have connectivity or whose connectivity is currently poor or disabled?

    I would greatly appreciate advice from anyone with experience in how best to handle this dilemma.
     
unityunity