- 官方地址 : https://unity3d.com/cn/services/ads/quick-start-guide
- 帮助文档网址:https://unityads.unity3d.com/help/index
1.Edit > Build Settings更改成Android/iOS
2.Window > Services点击Ads
3.开启Ads
4.新建一个脚本,将下面的代码复制进去
using UnityEngine;
using UnityEngine.Advertisements;
public class UnityAdsExample : MonoBehaviour
{
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;
}
}
}
5.新建一个Button,并挂上响应事件
6.运行效果
补充:
1.奖励玩家看广告
private void HandleShowResult (ShowResult result)
if (result == ShowResult.Finished) //判断广告是否被看完
{
//Add code to reward your player here!
//Give coins, etc
}
2.
首先登录Unity Ads Dashboard 使用UDN账户,并选择你的游戏项目。
选择平台.
从这里,您可以修改位置和其他特定于游戏的设置。