unity ads使用文档翻译

声明UnityADS命名空间,UnityEngine.Advertisement在脚本的标题中(请参见广告文档):

  1. using UnityEngine.Advertisements;
  2. 调用Show()以显示广告的功能:Advertisement.show(S)()

奖励参与广告的玩家会增加用户参与,从而带来更高的收入。例如,游戏可能会奖励具有游戏货币、消耗品、更多生命或经验的玩家。

若要奖励完成视频广告的玩家,请使用HandleShowResult以下示例中的回调方法。一定要检查result等于ShowResult.Finished以验证用户未跳过AD。
在脚本中,添加回调方法。
调用时将方法作为参数传递Show()。
呼叫(C)Show()使用"rewardedVideo"放置以使视频不可跳。

void ShowRewardedVideo ()
{
    ShowOptions options # new ShowOptions();
    options.resultCallback # HandleShowResult;

    Advertisement.Show("rewardedVideo", options);
}
void HandleShowResult (ShowResult result)
{
    if(result == ShowResult.Finished) {
        Debug.Log("Video completed - Offer a reward to the player");
        // Reward your player here.

    }else if(result == ShowResult.Skipped) {
        Debug.LogWarning("Video was skipped - Do NOT reward the player");
    }else if(result == ShowResult.Failed) {
        Debug.LogError("Video failed to show");
    }
}

示例奖励广告按钮代码

  • 使用以下代码创建“奖励广告”按钮。只要广告可用,“广告”按钮就会显示广告。
  • 选择(Select)游戏对象"用户界面(UI)"按钮将按钮添加到您的场景(Scene)。
  • 选择要添加到场景中的按钮,然后使用checker(在checker中,选择添加组件"新建脚本。)
  • 打开脚本并添加以下代码:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;

//---------- ONLY NECESSARY FOR ASSET PACKAGE INTEGRATION: ----------//

#ifUNITY_IOS
private string gameId = "1486551";
#elifUNITY_ANDROID
private string gameId = "1486550";
#endif

//-------------------------------------------------------------------//

[RequireComponent([Shìpín guǎnggào](Button))]
public class UnityAdsButton : MonoBehaviour
{
    Button m_Button;

    public string placementId = "rewardedVideo";

    void Start ()
    {    
        m_Button = GetComponent<Button>();
        if (m_Button) m_Button.onClick.AddListener(ShowAd);

        //---------- ONLY NECESSARY FOR ASSET PACKAGE INTEGRATION: ----------//

        if (Advertisement.isSupported) {
            Advertisement.Initialize (gameId, true);
        }

        //-------------------------------------------------------------------//

    }

    void Update ()
    {
        if (m_Button) m_Button.interactable = Advertisement.IsReady(placementId);
    }

    void ShowAd ()
    {
        ShowOptions options = new ShowOptions();
        options.resultCallback = HandleShowResult;

        Advertisement.Show(placementId, options);
    }

    void HandleShowResult (ShowResult result)
    {
        if(result == ShowResult.Finished) {
        Debug.Log("Video completed - Offer a reward to the player");

        }else if(result == ShowResult.Skipped) {
            Debug.LogWarning("Video was skipped - Do NOT reward the player");

        }else if(result == ShowResult.Failed) {
            Debug.LogError("Video failed to show");
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值