Search Unity

Unity reward ad [detect when they finished and player clicked close button]

Discussion in 'Unity Ads & User Acquisition' started by Orinuvan, Jun 22, 2019.

Thread Status:
Not open for further replies.
  1. Orinuvan

    Orinuvan

    Joined:
    Feb 3, 2019
    Posts:
    95
    Hi, how can I check to see if the the reward ad has finished and player clicked close button ? i have this code but I dont think it works in the editor so I want to know for sure if it will work when I will implement this on app store .. :

    Code (CSharp):
    1. public void ShowRewardedAd()
    2.     {
    3.         if (Advertisement.IsReady("rewardedVideo"))
    4.         {
    5.             var options = new ShowOptions { resultCallback = HandleShowResult };
    6.            
    7.             if (i <= 1)
    8.             {
    9.  
    10.                 AdResurrect = 1;
    11.  
    12.                 Advertisement.Show("rewardedVideo");
    13.                 Dead.SetActive(false);
    14.                 pause.SetActive(false);
    15.  
    16.                 Time.timeScale = 1;
    17.  
    18.  
    19.  
    20.             }
    21.         }
    22.     }
    23.  
    24.     private void HandleShowResult(ShowResult result)
    25.     {
    26.         switch (result)
    27.         {
    28.             case ShowResult.Finished:
    29.                 Debug.Log("The ad was successfully shown.");
    30.  
    31.                 if (player.BarHealth.transform.localScale.x >= 1)
    32.                 {
    33.                     player.BarHealth.transform.localScale = new Vector3(1f, 1f, 1f);
    34.                 }
    35.                 if (player.BarHealth.transform.localScale.x < 1)
    36.                 {
    37.                     player.BarHealth.transform.localScale = new Vector3(0.15f, 1f, 1f);
    38.  
    39.                 }
    40.                 REset.Reset();
    41.                 AdResurrect = 0;
    42.                 Time.timeScale = 1;
    43.                 //
    44.                 // YOUR CODE TO REWARD THE GAMER
    45.                 // Give coins etc.
    46.                 break;
    47.             case ShowResult.Skipped:
    48.                 Debug.Log("The ad was skipped before reaching the end.");
    49.                 break;
    50.             case ShowResult.Failed:
    51.                 Debug.LogError("The ad failed to be shown.");
    52.                 break;
    53.         }
    54.     }
    55. }

    Its an endless runner game that rewards the player with 15% health .
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @Orinuvan

    On line 12, you are calling Advertisement.Show, but you are not passing in the ShowOptions. Try:
    Advertisement.Show("rewardedVideo", options);
     
    Orinuvan likes this.
  3. Orinuvan

    Orinuvan

    Joined:
    Feb 3, 2019
    Posts:
    95
    Thanks I'll try
     
  4. Barkintosh

    Barkintosh

    Joined:
    Sep 18, 2017
    Posts:
    1
    Been trying for an hour to work with the IUnityAdsListener interface which isn't declared anywhere in the plugin.
    Tried your implementation and it worked like a charm, big thank
     
    Orinuvan likes this.
  5. Orinuvan

    Orinuvan

    Joined:
    Feb 3, 2019
    Posts:
    95
    Glad it helped ^^
     
Thread Status:
Not open for further replies.