文档

​
​

Development

User Acquisition

Monetization

工业

Unity Ads 变现

Unity Ads Android SDK

Unity Ads iOS SDK

Unity Ads SDK

Unity Ads 变现

Unity Ads Monetization
​
​
Unity 开发者指南
  • Unity SDK 概述
  • 安装适用于 Unity 的 Unity Ads SDK
  • 在 Unity 中初始化 SDK
  • 在 Unity 中实现插页式广告
  • 在 Unity 中实现奖励广告
  • 在 Unity 中实现横幅广告
Unity Ads API 参考
  • Unity Ads for Unity API 参考 (C#)
  1. 实现游戏增长
  2. Unity Ads
  3. 适用于 Unity 开发者的 Unity Ads SDK 集成指南

在 Unity 中实现奖励广告

在 Unity 项目中实现奖励广告。加载广告内容,通过 C# 脚本展示广告,并在广告展示完成后给予游戏内奖励。
阅读时间4 分钟
最后更新于 2 天前

对观看广告的玩家进行奖励可以增加用户参与度,从而带来更高收入。例如,游戏可以用游戏币、消耗品、额外生命数量或经验倍增法宝来奖励玩家。如需了解如何有效设计奖励广告的更多信息,请参阅有关变现策略的文档。
注意
从 SDK 4.4.1 版开始,Unity Ads 包在 Unity 编辑器中已更名为 Advertisement Legacy 包。 Advertisement Legacy 包 4.12 版仍能正常工作,但不会收到任何关于新功能或增强功能的进一步更新。 SDK 4.12 版支持 Apple 隐私清单更新,无计划对该包进一步更新。
要奖励玩家看完视频广告,请使用
ShowResult
结果实现一个回调方法来检查用户是否看完广告并应该获得奖励。

奖励广告按钮

使用按钮提示玩家选择观看广告是奖励视频广告的常见实现方式。可使用以下步骤中的示例代码来创建奖励广告按钮。只要有可用的广告内容,就会在按下按钮时展示广告。

奖励视频广告示例

要在 Unity 编辑器中配置按钮,请执行以下操作:
  1. 选择 Game Object(游戏对象)> UI > Button(按钮),将按钮添加到您的场景。
  2. 选择添加到场景中的按钮,然后使用 Inspector 为其添加脚本组件(选择 Add Component(添加组件)> New Script(新建脚本))。将脚本命名为
    RewardedAdsButton
    以便与类名匹配。
  3. 打开脚本,并添加以下代码:
using UnityEngine;using UnityEngine.UI;using UnityEngine.Advertisements;public class RewardedAdsButton : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener{ [SerializeField] Button _showAdButton; [SerializeField] string _androidAdUnitId = "Rewarded_Android"; [SerializeField] string _iOSAdUnitId = "Rewarded_iOS"; string _adUnitId = null; // This will remain null for unsupported platforms void Awake() { // Get the Ad Unit ID for the current platform: #if UNITY_IOS _adUnitId = _iOSAdUnitId; #elif UNITY_ANDROID _adUnitId = _androidAdUnitId; #endif // Disable the button until the ad is ready to show: _showAdButton.interactable = false; } // Call this public method when you want to get an ad ready to show. public void LoadAd() { // IMPORTANT!仅在初始化完成后加载内容(在此示例中,初始化在另一个脚本中处理)。 Debug.Log("Loading Ad: " + _adUnitId); Advertisement.Load(_adUnitId, this); } // If the ad successfully loads, add a listener to the button and enable it: public void OnUnityAdsAdLoaded(string adUnitId) { Debug.Log("Ad Loaded: " + adUnitId); if (adUnitId.Equals(_adUnitId)) { // Configure the button to call the ShowAd() method when clicked: _showAdButton.onClick.AddListener(ShowAd); // Enable the button for users to click: _showAdButton.interactable = true; } } // Implement a method to execute when the user clicks the button: public void ShowAd() { // Disable the button: _showAdButton.interactable = false; // Then show the ad: Advertisement.Show(_adUnitId, this); } // Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward: public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState) { if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED)) { Debug.Log("Unity Ads Rewarded Ad Completed"); // Grant a reward. } } // Implement Load and Show Listener error callbacks: public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message) { Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}"); // Use the error details to determine whether to try to load another ad. } public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message) { Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}"); // Use the error details to determine whether to try to load another ad. } public void OnUnityAdsShowStart(string adUnitId) { } public void OnUnityAdsShowClick(string adUnitId) { } void OnDestroy() { // Clean up the button listeners: _showAdButton.onClick.RemoveAllListeners(); }}
后续步骤:请参阅在 Unity 中实现横幅广告。

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。

  • 在本页上
    • 奖励广告按钮

      • 奖励视频广告示例


报告此页面的问题