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

Detect ad close button

Discussion in 'Scripting' started by Rotzak, Aug 10, 2018.

  1. Rotzak

    Rotzak

    Joined:
    Jul 11, 2018
    Posts:
    92
    Hello guys,

    I have Unityads integrated in my car racing game. When you die once you can get a second chance by watching an ad. After the ad is finished there is a countdown: 3, 2,1, GO!

    The countdown animation (bool adFinished = true) starts playing after the ad is finished see this code (line 27-30):

    Code (CSharp):
    1. using UnityEngine.Advertisements;
    2. using UnityEngine.UI;
    3.  
    4. public class PlayAd : MonoBehaviour
    5. {
    6.     public bool adFinished;
    7.  
    8.     void Start()
    9.     {
    10.         Advertisement.Initialize("*******");
    11.     }
    12.  
    13.     public void ShowAd()
    14.     {
    15.         if (Advertisement.IsReady())
    16.         {
    17.             Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleAdResult });
    18.         }
    19.  
    20.         gameObject.SetActive(false);
    21.     }
    22.  
    23.     private void HandleAdResult(ShowResult result)
    24.     {
    25.         switch (result)
    26.         {
    27.             case ShowResult.Finished:
    28.                 Debug.Log("Revive!");
    29.                 adFinished = true;
    30.                 break;
    31.             case ShowResult.Skipped:
    32.                 Debug.Log("Player did not fully watch the ad");
    33.                 break;
    34.             case ShowResult.Failed:
    35.                 Debug.Log("Player failed to launch the ad");
    36.                 break;
    37.         }
    38.     }
    39. }
    My problem is the countdown animation starts playing when the ad is finished but this is before the player clicked close button on the ad video! Any idea how I can detect when a player hit the close button of an ad because on ShowResult.Finished will just never work.

    I've tried to make an button active when ad is finished and then when this button would be clicked the animation would start playing, but the click doesn't go through...
     
  2. Rotzak

    Rotzak

    Joined:
    Jul 11, 2018
    Posts:
    92
  3. Rioneer

    Rioneer

    Joined:
    Nov 27, 2013
    Posts:
    51
    I don't know but you can implement a workaround by adding an additional "resume playing" button which the player can click after closing the ad window.
     
    pdtbinh and Rotzak like this.
  4. Jiry_XD

    Jiry_XD

    Joined:
    Aug 3, 2020
    Posts:
    20
    Also searching a solution for this. Does anybody perhaps know a solution for this?
     
    Last edited: Apr 11, 2021