Google AdMob與UnityADs在游戲中進行廣告接入,谷歌廣告unity調用方法閃退Google AdMob與UnityADs在游戲中進行廣告接入框架視圖效果圖關鍵代碼GoogleAdManagerusing UnityEngine;using System.Collections;using GoogleM......
框架視圖
效果圖
關鍵代碼
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);//參數:廣告id,廣告尺寸(橫幅),位置;
//構建廣告
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;
}
}
}
特別聲明:以上文章內容僅代表作者本人觀點,不代表ESG跨境電商觀點或立場。如有關于作品內容、版權或其它問題請于作品發表后的30日內與ESG跨境電商聯系。
二維碼加載中...
使用微信掃一掃登錄
使用賬號密碼登錄
平臺顧問
微信掃一掃
馬上聯系在線顧問
小程序
ESG跨境小程序
手機入駐更便捷
返回頂部