unityads.init()

类型 函数
返回值
版本 发行版 2024.3703
关键字 广告、宣传、Unity 广告、init
另请参阅 unityads.show()
unityads.*

概述

unityads.init() 初始化 Unity Ads 插件。必须执行此调用,并且必须在执行其他 Unity Ads 调用(例如 unityads.show()unityads.load())之前执行此调用。

语法

unityads.init( listener, params )
listener (必需)

侦听器. 侦听器函数,将接收 adsRequest 事件。

params (必需)

. 包含 Unity Ads 初始化值,有关详细信息,请参阅下一部分的表。

参数参考

params 表包括 Unity Ads 初始化的参数。

gameId (必需)

字符串. 应用程序的游戏 ID,从 Unity Ads 仪表板 收集。

testMode (可选)

布尔. 将此值设置为 true 以启用测试广告。默认值为 false

示例

local unityads = require( "plugin.unityads.v4" )

-- 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" } )