Skip to content

Return To Play Ad Object

d.eshenko edited this page Oct 18, 2022 · 10 revisions

⚡ Before you start
Make sure you have correctly initialized Mediaiton Manager via Script or Unity Editor.

Implementation by UnityEditor | Script C#


This guide explains how to integrate interstitial ads into a Unity app.

Add a ReturnToPlayAdObject to the scene

  1. Add a GameObject to your scene using GameObject > Create Empty in the Unity Editor.
  2. Add Component CleverAdsSolutions/Return To Play Ad Object in the inspector to new GameObject.
  3. Select Manager ID from the settings asset for each runtime platform.
  4. Check flag allowReturnToPlayAd

image

⭐ An ReturnToPlayAdObject does not have any rendered components. Therefore, you can place the GameObject anywhere in the scene.

Load Ad callbacks

  • On Ad Loaded
    The event is invoked when the ad has finished loading.
  • On Ad Failed To Load
    The event is invoked when the ad fails to load. The Message parameter describes the type of failure that occurred.

Content callbacks

  • On Ad Failed To Show
    The event is invoked when the ad failed to show. The Message parameter describes the type of failure that occurred.
  • On Ad Shown
    The event is invoked when the ad is shown.
  • On Ad Clicked
    The event is invoked when the user clicks on the ad.
  • On Ad Closed
    The event is invoked when the ad is closed.

⭐ Using Ad objects automatically enable Execute Events On Unity Thread and invoke all callbacks in the Unity Thread to safe use of Unity API.

Unity Events sample

You can implement functions that correspond to ad callbacks. For example, if you want to handle when the ad fails to shown:

  1. Create a function compatible with the ad callback in custom component.
public void OnReturnToPlayAdFailedToShow(string reason) {
    Debug.Log("ReturnToPlay ad failed to show: " + reason);
}
  1. Attach the script which contains the above function to any GameObject in the scene.
  2. Click the + button, then drag & drop the GameObject that you've attached the script to.
  3. Select the function that you want to link to the ad callback. For the parameterized ad callbacks, select the function to accept the dynamic variable so you can get the parameter value from the SDK.

Use ReturnToPlayAdObject from script

Get the ReturnToPlay ad instance from the script:

ReturnToPlayAdObject adObject = adObject.GetComponent<ReturnToPlayAdObject>();

Enable ReturnToPlay ad:

adObject.allowReturnToPlayAd = true;

Disable ReturnToPlay ad:

adObject.allowReturnToPlayAd = false;

What’s Next?

Clone this wiki locally