Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Detect ad close button

Discussion in 'Scripting' started by Rotzak, Aug 10, 2018 at 11:05 AM.

  1. Rotzak

    Rotzak

    Joined:
    Jul 11, 2018
    Posts:
    56
    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:
    56
  3. Nick4

    Nick4

    Joined:
    Nov 27, 2013
    Posts:
    46
    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.