Search Unity

Admob dont reward if add is clicked

Discussion in 'Unity Ads & User Acquisition' started by Flawless83, Jul 17, 2018.

  1. Flawless83

    Flawless83

    Joined:
    Dec 7, 2016
    Posts:
    136
    When i use addmo0b, if a user click the add it they dont get rewarded cause the game restarts, here is my code.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System;
    5. using GoogleMobileAds.Api;
    6.  
    7.     public class Adds : MonoBehaviour
    8. {
    9.     private RewardBasedVideoAd rewardBasedVideo;
    10.     public GameObject ButtonDisable;
    11.     PlayMakerFSM PurchaseFSM;
    12.  
    13.  
    14.     public void Start()
    15.     {
    16.  
    17.         PurchaseFSM = GameObject.Find("Purchase").GetComponent<PlayMakerFSM>();
    18.         ButtonDisable.SetActive(false);
    19.  
    20.         // Get singleton reward based video ad reference.
    21.         this.rewardBasedVideo = RewardBasedVideoAd.Instance;
    22.  
    23.         // Called when an ad request has successfully loaded.
    24.         rewardBasedVideo.OnAdLoaded += HandleRewardBasedVideoLoaded;
    25.         // Called when an ad request failed to load.
    26.         rewardBasedVideo.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
    27.         // Called when an ad is shown.
    28.         rewardBasedVideo.OnAdOpening += HandleRewardBasedVideoOpened;
    29.         // Called when the ad starts to play.
    30.         rewardBasedVideo.OnAdStarted += HandleRewardBasedVideoStarted;
    31.         // Called when the user should be rewarded for watching a video.
    32.         rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
    33.         // Called when the ad is closed.
    34.         rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
    35.         // Called when the ad click caused the user to leave the application.
    36.         rewardBasedVideo.OnAdLeavingApplication += HandleRewardBasedVideoLeftApplication;
    37.  
    38.         this.RequestRewardBasedVideo();
    39.     }
    40.  
    41.     private void RequestRewardBasedVideo()
    42.     {
    43.         #if UNITY_ANDROID
    44.         string adUnitId = "ca-app-pub-1405555723492700/7525960092";
    45.         #elif UNITY_IPHONE
    46.         string adUnitId = "ca-app-pub-3940256099942544/1712485313";
    47.         #else
    48.         string adUnitId = "unexpected_platform";
    49.         #endif
    50.  
    51.         // Create an empty ad request.
    52.         AdRequest request = new AdRequest.Builder().Build();
    53.         // Load the rewarded video ad with the request.
    54.         this.rewardBasedVideo.LoadAd(request, adUnitId);
    55.         }
    56.  
    57.         public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
    58.         {
    59.         MonoBehaviour.print("HandleRewardBasedVideoLoaded event received");
    60.         }
    61.  
    62.         public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    63.         {
    64.         MonoBehaviour.print(
    65.         "HandleRewardBasedVideoFailedToLoad event received with message: "
    66.         + args.Message);
    67.         }
    68.  
    69.         public void HandleRewardBasedVideoOpened(object sender, EventArgs args)
    70.         {
    71.         MonoBehaviour.print("HandleRewardBasedVideoOpened event received");
    72.         }
    73.  
    74.         public void HandleRewardBasedVideoStarted(object sender, EventArgs args)
    75.         {
    76.         MonoBehaviour.print("HandleRewardBasedVideoStarted event received");
    77.         }
    78.  
    79.         public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
    80.         {
    81.         MonoBehaviour.print("HandleRewardBasedVideoClosed event received");
    82.     }
    83.  
    84.         public void HandleRewardBasedVideoRewarded(object sender, Reward args)
    85.         {
    86.         string type = args.Type;
    87.         double amount = args.Amount;
    88.         MonoBehaviour.print(
    89.         "HandleRewardBasedVideoRewarded event received for "
    90.         + amount.ToString() + " " + type);
    91.         PurchaseFSM.Fsm.Event("ShowAdd");
    92.     }
    93.  
    94.         public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args)
    95.         {
    96.         PurchaseFSM.Fsm.Event("ShowAdd");
    97.         MonoBehaviour.print("HandleRewardBasedVideoLeftApplication event received");
    98.      
    99.     }
    100.  
    101.         public void Reward()
    102.         {
    103.         if (rewardBasedVideo.IsLoaded()) {
    104.             ButtonDisable.SetActive(true);
    105.             rewardBasedVideo.Show();
    106.  
    107.         }
    108.         }
    109.  
    110.         }
    all works just dont if they click on the add, then they get nothing, is there a way to go back to the game where it was when the game exit to go to page of the add. also do anyone now why the buttons are so slow need to click many times before add show up?
     
    Last edited: Jul 17, 2018