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跨境小程序
手机入驻更便捷
返回顶部