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
  4. Dismiss Notice

Big ad reward problem

Discussion in 'Scripting' started by Shayke, Apr 25, 2018.

  1. Shayke

    Shayke

    Joined:
    Dec 8, 2017
    Posts:
    352
    Hi, i released my game and i noticed that when i click on the button fast enough before the ad appears the player gets the reward more than once!
    Code (CSharp):
    1.     public void ShowAd30secForCoins()
    2.     {
    3.         if (Advertisement.IsReady())
    4.         {
    5.             Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleResult30ForCoin });
    6.         }
    7.     }
    8.  
    9.     public void HandleResult30(ShowResult result)
    10.     {
    11.         switch (result)
    12.         {
    13.             case ShowResult.Finished:
    14.                 Spins += 3;
    15.                
    16.                 //  Debug.Log("Win30");
    17.                 break;
    18.             case ShowResult.Skipped:
    19.                 //  Debug.Log("Skip");
    20.                 break;
    21.             case ShowResult.Failed:
    22.                 //  Debug.Log("Fail");
    23.                 break;
    24.         }
    25.     }
     
  2. BlingHan

    BlingHan

    Joined:
    Mar 27, 2018
    Posts:
    2
    Why don't you do something like?

    Code (CSharp):
    1. bool rewarded;
    2.  
    3. public void ShowAd30secForCoins()
    4.     {
    5.         if (Advertisement.IsReady())
    6.         {
    7.             rewarded = false;
    8.             Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleResult30ForCoin });
    9.         }
    10.     }
    11.     public void HandleResult30(ShowResult result)
    12.     {
    13.         switch (result)
    14.         {
    15.             case ShowResult.Finished:
    16.                 if(!rewarded)
    17.                     Spins += 3;
    18.                 rewarded = true;
    19.              
    20.                 //  Debug.Log("Win30");
    21.                 break;
    22.             case ShowResult.Skipped:
    23.                 //  Debug.Log("Skip");
    24.                 break;
    25.             case ShowResult.Failed:
    26.                 //  Debug.Log("Fail");
    27.                 break;
    28.         }
    29.     }
    Might not be the prettiest fix, but should work
     
  3. Shayke

    Shayke

    Joined:
    Dec 8, 2017
    Posts:
    352
    Nope, That's not working.
    It's like doing the same.
    Maybe i can make an Invoke function that after a second it can be pressed again.

    Edit: Well, the invoke with your solution work.
    A bit lame but that's enough lol.
    Thanks
     
    Last edited: Apr 25, 2018