unityads.init()

类型 功能
返回值
修订 发行版 2024.3703
关键词 广告、宣传、Unity 广告、init
另请参阅 unityads.show()
unityads.*

概述

unityads.init() 初始化 Unity Ads 插件。必须执行此调用并先于其他 Unity Ads 调用,例如 unityads.show()

初始化完成后,Unity Ads 将自动开始加载您在 Unity Ads 控制面板 中配置的展示位置 ID 的广告。

语法

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

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

params (必需)

Table. 包含 Unity Ads 初始化值,请参阅下一部分以获取详细信息。

参数参考

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

gameId (必需)

String. 该应用程序的游戏 ID,可从 Unity Ads 控制面板 中获取。

testMode (可选)

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

示例

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