iT邦幫忙

0

Unity串廣告 - Unity實作篇

Goo 2025-07-19 14:55:53456 瀏覽
  • 分享至 

  • xImage
  •  

一段時間沒在Unity串廣告, Unity又升級做法了
寫這篇時是2025年7月,這時新版的做法是用LevelPlay與Ads Mediation
新版可以選擇的廣告商變得更多了, 但是設定也更複雜了

在開始之前提一下,以前的Unity Ads還是可以使用,不過官方不再更新支援,想用可以參考:https://goocoding.blogspot.com/2023/07/unity-ads.html

接下來就是在Unity專案裡實做廣告串接:

連接Unity Cloud

Unity專案需要連接Unity Cloud才能運行Ads Mediation,連接設定可以參考:https://ithelp.ithome.com.tw/articles/10255545

安裝Ads Mediation

在PackageManager中的Unity Registry可以找到Ads Mediation安裝
本篇的版本用的是8.10.0
https://ithelp.ithome.com.tw/upload/images/20250718/20135260zd5wUgMUBq.png

實作初始化LevelPlay

創建一個腳本運行LevelPlay的初始化,程式碼範例如下圖:
https://ithelp.ithome.com.tw/upload/images/20250718/20135260nSIdx0dVw3.jpg
要注意的是,UnityServices初始化完成後才能進行LevelPlay的初始化
還有LevelPlay.Init需要的appKey可以從LevelPlay的後台->Apps( https://platform.ironsrc.com/partners/home )找到
如果後台沒有的話,可以參考此篇設定: https://ithelp.ithome.com.tw/articles/10373000

實作廣告呼叫

接著實作廣告的讀取與呼叫
本範例的腳本是綁在(UGUI的)Button物件上,點擊時呼叫ShowAd()
如果你沒有Button物件的話,我建議你有
程式碼範例如下圖:
https://ithelp.ithome.com.tw/upload/images/20250718/20135260dzGLlEDzGg.jpg
其中new LevelPlayRewardedAd時要用到的adUnitId可以從LevelPlay的後台->Setup->Ad units
( https://platform.ironsrc.com/partners/next/adUnits/ )找到
後台的ad unit設定可以參考此篇: https://ithelp.ithome.com.tw/articles/10373000
在這個範例中,你可以利用AdsCompleteEvent來呼叫廣告播放完成後的遊戲邏輯(ex: 復活、給次數、etc...)


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言