Google AdMob與UnityADs在游戲中進(jìn)行廣告接入,谷歌廣告unity調(diào)用方法閃退Google AdMob與UnityADs在游戲中進(jìn)行廣告接入框架視圖效果圖關(guān)鍵代碼GoogleAdManagerusing UnityEngine;using System.Collections;using GoogleM......
框架視圖
效果圖
關(guān)鍵代碼
GoogleAdManager
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;//摻入廣告命名空間
public class GoogleAdManager : MonoBehaviour
{
public string adUnitId = caapppub5711132426115648/1023732213;
// Use this for initialization
void Start()
{
//橫幅廣告
//摻入廣告
BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);//參數(shù):廣告id,廣告尺寸(橫幅),位置;
//構(gòu)建廣告
AdRequest request = new AdRequest.Builder().Build();
//加載廣告
bannerView.LoadAd(request);
//bannerView.Show ();
}
}
UnityAd
using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements;
public class UnityAd : MonoBehaviour
{
void Start()
{
Advertisement.Initialize(1321938, true);
}
public void ShowAd()
{
print(Advertisement.IsReady());
if (Advertisement.IsReady())
{
Advertisement.Show();
}
}
void Update()
{
if (Advertisement.IsReady() !Advertisement.isShowing)
{
ShowAd();
}
}
public void ShowRewardedAd()
{
if (Advertisement.IsReady(rewardedVideo))
{
var options = new ShowOptions { resultCallback = HandleShowResult };
Advertisement.Show(rewardedVideo, options);
}
}
private void HandleShowResult(ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
Debug.Log(The ad was successfully shown.);
//
// YOUR CODE TO REWARD THE GAMER
// Give coins etc.
break;
case ShowResult.Skipped:
Debug.Log(The ad was skipped before reaching the end.);
break;
case ShowResult.Failed:
Debug.LogError(The ad failed to be shown.);
break;
}
}
}
特別聲明:以上文章內(nèi)容僅代表作者本人觀點(diǎn),不代表ESG跨境電商觀點(diǎn)或立場。如有關(guān)于作品內(nèi)容、版權(quán)或其它問題請于作品發(fā)表后的30日內(nèi)與ESG跨境電商聯(lián)系。
二維碼加載中...
使用微信掃一掃登錄
使用賬號密碼登錄
平臺(tái)顧問
微信掃一掃
馬上聯(lián)系在線顧問
小程序
ESG跨境小程序
手機(jī)入駐更便捷
返回頂部