unityads.show()

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

Overview

Shows a Unity Ads video interstitial or rewarded video ad.

Note

Unlike the previous plugin you need load placement IDs with unityads.load() and will get a event.phase loaded

Syntax

unityads.show( placementId )
placementId (required)

String. One of the placement IDs you've configured in the Unity Ads dashboard.

Example

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

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

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

    --Load ad before we show
    unityads.load("YOUR_UNITYADS_PLACEMENT_ID")

    end
end

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



-- Sometime later, show an ad
if ( unityads.isLoaded( "YOUR_UNITYADS_PLACEMENT_ID" ) ) then
    unityads.show( "YOUR_UNITYADS_PLACEMENT_ID" )
end