unityads.init()

Type Function
Return value none
Revision 2018.3321
Keywords ads, advertising, Unity Ads, init
See also unityads.show()
unityads.*

Overview

unityads.init() initializes the Unity Ads plugin. This call is required and must be executed before making other Unity Ads calls such as unityads.show().

Once initialized, Unity Ads will automatically start loading ads for the placement IDs you've configured in the Unity Ads dashboard.

Syntax

unityads.init( listener, params )
listener (required)

Listener. Listener function that will receive adsRequest events.

params (required)

Table. Table containing Unity Ads initialization values — see the next section for details.

Parameter Reference

The params table includes parameters for Unity Ads initialization.

gameId (required)

String. The game ID for your app, gathered from the Unity Ads dashboard.

testMode (optional)

Boolean. Set this value to true to enable test ads. Default is false.

Example

local unityads = require( "plugin.unityads" )

-- Unity Ads listener function
local function adListener( event )

    if ( event.phase == "init" ) then  -- Successful initialization
        print( event.provider )
    end
end

-- Initialize the Unity Ads plugin
unityads.init( adListener, { gameId="YOUR_UNITYADS_GAME_ID" } )