Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Detect ad close button

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

  1. Rotzak


    Jul 11, 2018
    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;
    4. public class PlayAd : MonoBehaviour
    5. {
    6.     public bool adFinished;
    8.     void Start()
    9.     {
    10.         Advertisement.Initialize("*******");
    11.     }
    13.     public void ShowAd()
    14.     {
    15.         if (Advertisement.IsReady())
    16.         {
    17.             Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleAdResult });
    18.         }
    20.         gameObject.SetActive(false);
    21.     }
    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


    Jul 11, 2018
  3. Nick4


    Nov 27, 2013
    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.
    Rotzak likes this.