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

Admob Rewarded Video problem

Discussion in 'Scripting' started by Jip1912, Sep 27, 2016.

  1. Jip1912

    Jip1912

    Joined:
    Mar 13, 2015
    Posts:
    314
    Hi,

    I use this script but I don't get any coins after watching the ad, how do I do this in the right way?
    (I want the player to get coinT.coins += 15;)
    The public void RewardedVideo is attachted to a button.
    Code (CSharp):
    1. public void RewardedVideo()
    2.     {
    3.         #if UNITY_ANDROID
    4.         string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxx";
    5.         #elif UNITY_IPHONE
    6.         string adUnitId = "INSERT_AD_UNIT_HERE";
    7.         #else
    8.         string adUnitId = "unexpected_platform";
    9.         #endif
    10.  
    11.         RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
    12.  
    13.         if (rewardBasedVideo.IsLoaded ()) {
    14.             rewardBasedVideo.Show ();
    15.         }
    16.  
    17.         rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
    18.     }
    19.  
    20.     }
    21.  
    22.         public void HandleRewardBasedVideoRewarded(object sender, Reward args)
    23.         {
    24.         CoinText coinT = cText.GetComponent<CoinText>();
    25.         string type = args.Type;
    26.         double amount = args.Amount;
    27.         coinT.coins += 15;
    28.         print("User rewarded with: " + amount.ToString() + " " + type);
    29.         }
     
  2. CloudKid

    CloudKid

    Joined:
    Dec 13, 2015
    Posts:
    207
    Try and move
    Code (CSharp):
    1.  rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
    before you call the show method. Maybe that will work?

    If not, you have to research in what situation OnAdRewarded is called, and why yours did not work.
     
  3. Jip1912

    Jip1912

    Joined:
    Mar 13, 2015
    Posts:
    314
    I did what you said, but actually nothing happends when I click on the button now. (It didn't before I did what you said, but it used to work).

    Forgot to mention that it is now a test ad

    Code (CSharp):
    1.     void Start()
    2.     {
    3.         #if UNITY_ANDROID
    4.         string adUnitId = "ca-app-pub-xxxxxxxxx";
    5.         #elif UNITY_IPHONE
    6.         string adUnitId = "INSERT_AD_UNIT_HERE";
    7.         #else
    8.         string adUnitId = "unexpected_platform";
    9.         #endif
    10.  
    11.         RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
    12.         AdRequest request = new AdRequest.Builder()
    13.         .AddTestDevice(AdRequest.TestDeviceSimulator)       // Simulator.
    14.         .AddTestDevice("19E0357---------------")  // My test device.
    15.         .Build();
    16.  
    17.         rewardBasedVideo.LoadAd(request, adUnitId);
    18.  
    19.     }
    Do you know how I can get it to work?
     
  4. Jip1912

    Jip1912

    Joined:
    Mar 13, 2015
    Posts:
    314
    You got a solution?
     
  5. Jip1912

    Jip1912

    Joined:
    Mar 13, 2015
    Posts:
    314
    Does someone know how to use the admob reward video?
     
  6. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    855
    Be sure you execute it in the unity main thread. Implement JobEventQueue.
    Admob uses other thread, I think.
     
    xVergilx likes this.