Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity Ads no result

Discussion in 'Unity Ads & User Acquisition' started by Yash987654321, Apr 27, 2015.

  1. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    Hello,
    I am using Unity Ads and I managed to show ads in game, but when it came to result, I am getting none.
    The script I am using (its only the Ad function)

    Code (CSharp):
    1.     public void ThrowAd ()
    2.     {
    3.      
    4.         if (Advertisement.isSupported) {
    5.          
    6.             ShowOptions options = new ShowOptions();
    7.             ShowResult result = new ShowResult();
    8.             Advertisement.Initialize ("My Unpublished Game ID", false);
    9.             if (Advertisement.isReady (zoneId: "rewardedVideoZone")) {
    10.              
    11.                 options.pause = true;
    12.                 AdsD = AdsDelay;
    13.                 Advertisement.Show("rewardedVideoZone");
    14.              
    15.             } else {
    16.              
    17.                 AdDetails.text = "Ad not loaded";
    18.              
    19.             }
    20.             options.resultCallback = results => {
    21.              
    22.                 switch (result) {
    23.                  
    24.                 case(ShowResult.Failed):
    25.                  
    26.                     AdDetails.text = "Ad failed!";
    27.                  
    28.                     break;
    29.                  
    30.                 case(ShowResult.Finished):
    31.                  
    32.                     if (AdType == 1) {
    33.                      
    34.                         AdDetails.text = "You just earned a gem!";
    35.                      
    36.                     } else {
    37.                      
    38.                         AdDetails.text = "Thanks for watching the Ad";
    39.                      
    40.                     }
    41.                  
    42.                     break;
    43.                  
    44.                 case(ShowResult.Skipped):
    45.                  
    46.                     AdDetails.text = "Ad was skipped :(";
    47.                  
    48.                     break;
    49.                 }
    50.              
    51.             };
    52.         }
    53.     }
    It shows the ad perfectly but do not give any reward/message to me. (Unity Remote not working so cant debug log (Already tried text fields)).
    Also it gives me a error while viewing the picture ad (yes videos are not coming) that says 'Video Playback Error'. Please Help!
     
  2. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    540
    The Video Playback Error occurs when the video fails to stream due to poor network conditions.

    There are a few of issues with your code:
    1. You call initialize shortly before the Show() method; Unity Ads won't be ready in time to show.
    2. When calling the Show() method, you left out the options parameter.
    3. You assign a value to resultCallback after the point that it should be referenced.
    Code (CSharp):
    1. public string gameID;
    2. public bool enableTestMode;
    3.  
    4. void Start ()
    5. {
    6.     if (Advertisement.isSupported)
    7.     {
    8.         Advertisement.Initialize(gameID,enableTestMode)
    9.     }
    10. }
    11.  
    12. public void ThrowAd ()
    13. {
    14.     if (Advertisement.isReady("rewardedVideoZone"))
    15.     {
    16.         ShowOptions options = new ShowOptions();
    17.         options.resultCallback = results => {
    18.             switch (result)
    19.             {
    20.             case(ShowResult.Failed):
    21.                 AdDetails.text = "Ad failed!";
    22.                 break;
    23.  
    24.             case(ShowResult.Finished):
    25.                 if (AdType == 1) AdDetails.text = "You just earned a gem!";
    26.                 else AdDetails.text = "Thanks for watching the Ad";
    27.                 break;
    28.  
    29.             case(ShowResult.Skipped):
    30.                 AdDetails.text = "Ad was skipped :(";
    31.                 break;
    32.             }
    33.         };
    34.         options.pause = true;
    35.      
    36.         AdsD = AdsDelay;
    37.      
    38.         Advertisement.Show("rewardedVideoZone",options);
    39.     }
    40.     else AdDetails.text = "Ad not loaded";
    41. }
     
  3. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    ok thanks :) my network was slow so video playback error was occurring. thanks it solved my problem
     
  4. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    so can I allow precache in start/awake.
     
  5. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    edit- Again if i skip/complete the ad no result still
     
  6. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    I edited the script still not working
    Code (CSharp):
    1. public void ThrowAd ()
    2.     {
    3.         if (Advertisement.isReady ("rewardedVideoZone")) {
    4.             ShowOptions options = new ShowOptions ();
    5.             options.pause = true;
    6.             options.resultCallback = HandleShowResult;
    7.             AdsD = AdsDelay;
    8.             Advertisement.Show ("rewardedVideoZone");
    9.  
    10.         } else {
    11.  
    12.             AdDetails.text = "Ad not loaded";
    13.  
    14.         }
    15.     }
    16.     void HandleShowResult(ShowResult result) {
    17.        
    18.         switch (result) {
    19.         case(ShowResult.Failed):
    20.             AdDetails.text = "Ad failed!";
    21.             break;
    22.            
    23.         case(ShowResult.Finished):
    24.             if (AdType == 1) {
    25.                 AdDetails.text = "You just earned a gem!";
    26.             } else {
    27.                 AdDetails.text = "Thanks for watching the Ad";
    28.             }
    29.             break;
    30.            
    31.         case(ShowResult.Skipped):
    32.             AdDetails.text = "Ad was skipped :(";
    33.             break;
    34.         }
    35.     }
    :(:(:(:(:(:(:(
    Please help only the Ad system is left in my game
     
  7. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    540
    You're still not passing the options parameter when calling show. You need to pass options like so:
    Code (CSharp):
    1. Advertisement.Show ("rewardedVideoZone",options);
    Without that parameter, the result callback will not be called.
     
    Yash987654321 likes this.
  8. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    oh I see I need the second parameter of options to make the script follow the functions. I try it Thanks
    :)
     
  9. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    Thanks a lot. It is working now!
     
  10. Nirav-Madhani

    Nirav-Madhani

    Joined:
    Jan 8, 2014
    Posts:
    27
    Can anyone post complete error-free script ?
     
  11. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    unity-nikkolai likes this.