ドキュメント

​
​

Development

User Acquisition

Monetization

産業

Cloud Code

Open Unity Dashboard

Cloud Code

LiveOps
​
​
Cloud Code
  • Overview
  • Get started
  • Server authority
  • Cloud Code C# modules
  • Cloud Code JavaScript scripts
    • Overview
    • Get started
    • Concepts
    • Tutorials
      • Run scripts
      • Write scripts
      • Interact with cross-player data
      • Integrate with CI/CD
      • Use Access Control
      • Test run a script
      • Integrate with other Unity Services
      • Integrate with external services
      • Use Cases
        • Server time anti-cheat
        • Redeemable coupons
        • Daily Rewards
        • Use Lobby
        • Advanced use cases
    • Reference
  • Logging
  • Use-case samples
  • Privacy and consent
  1. Cloud Code
  2. ユースケース

1 日ごとのゲーム内報酬

Implement a daily rewards system that brings players back every day.
読み終わるまでの所要時間 6 分
最終更新 5ヶ月前

1 日ごとのゲーム内報酬は、すべてのジャンルのゲームで使用される人気のゲームメカニクスになっており、特にフリートゥプレイのタイトルで人気です。これらは、プレイヤーが毎日戻ってくるようにする魅力的な方法を提供すると同時に、純粋に装飾的なスキンやアバターからインベントリアイテムやゲーム内通貨まで、さまざまなアイテムを獲得できるようにします。
Cloud Code の他の Unity サービスと簡単に統合する機能により、1 日ごとのゲーム内報酬に関するロジックをビルドするための優れた選択肢になります。Economy でアイテムと通貨、Remote Config で確率を定義し、基礎となるアルゴリズムを Cloud Code で記述できます。これにより、ゲームクライアントを更新する必要なしに、1 日ごとのゲーム内報酬のロジックをその場で変更できます。
例えば、以下のような使い方が可能です。
  • 一部のアイテムの可用性を低減します。
  • 報酬として受け取れるアイテム数を増やします
  • プレイヤーがレアアイテムを重複して受け取ることを防ぐ追加の検証を入れます。
  • Remote Config キャンペーンを通じてアイテムと確率を変更します。

設定

以下の例は、複数のペット用おもちゃを Economy でインベントリアイテムとして定義する方法を示します。Cloud Code スクリプトですべてを結びつける前に、Remote Config で 1 日ごとのゲーム内報酬パラメーターを定義できます。

Economy

このゲームメカニクスの作成の最初のステップでは、Economy でインベントリアイテムタイプのゲーム内報酬を定義します。
Unity Dashboard に移動し、左のナビゲーションバーから Economy を選択します。
Economy で以下のインベントリアイテムを作成します。
  1. ID
    TOY_CHOCO
    のインベントリアイテム
    Choco
  2. ID
    TOY_JOJO
    のインベントリアイテム
    Jojo
  3. ID
    TOY_KIKI
    のインベントリアイテム
    Kiki
注
Cloud Code スクリプトで使用する前に、Economy 設定を公開する必要があります。

Remote Config

Remote Config を使用して、キー
DAILY_REWARDS_VARIABLES
で 1 日ごとのゲーム内報酬パラメーターをカスタム JSON 値として定義できます。
JSON
{ "rewards": [ {"id": "TOY_CHOCO", "probability": 10}, {"id": "TOY_JOJO", "probability": 65}, {"id": "TOY_KIKI", "probability": 80} ]}
注
キーと値のペアを保存して、Cloud Code スクリプトで使用可能にします。

1 日ごとのゲーム内報酬のスクリプト

設定が行われると、シンプルな加重ランダムアルゴリズムを使用してプレイヤーにランダムなおもちゃを贈呈するように Economy および Remote Config を操作するシンプルなスクリプトを記述できます。
JavaScript
/* * Retrieve the daily rewards configuration from Remote Config * Select a random item from the configuration and gift the item to the player in Economy * Note: the Economy configuration needs to be published and Remote Config values need to be saved before they are available in Cloud Code scripts. * */const { InventoryApi } = require('@unity-services/economy-2.4');const { SettingsApi } = require('@unity-services/remote-config-1.1');const _ = require('lodash-4.17');const REMOTE_CONFIG_VARIABLES_KEY = 'DAILY_REWARDS_VARIABLES';module.exports = async ({ context }) => { // Initialize the Economy and Remote Config API clients using the player credentials const { projectId, environmentId, playerId } = context; const inventoryApi = new InventoryApi(context); const remoteConfigApi = new SettingsApi(context); // Fetch the daily rewards configuration from Remote Config const remoteConfigResponse = await remoteConfigApi.assignSettingsGet( projectId, environmentId, 'settings', [REMOTE_CONFIG_VARIABLES_KEY] ); // Extract the daily rewards from the response const dailyRewardsConfig = remoteConfigResponse?.data?.configs?.settings?.[REMOTE_CONFIG_VARIABLES_KEY]; const dailyRewards = dailyRewardsConfig?.rewards; // Pick a random reward from the options const reward = selectRandomReward(dailyRewards); // Gift the reward to the player await inventoryApi.addInventoryItem({ projectId, playerId, addInventoryRequest: { inventoryItemId: reward.id } }); return { reward: reward.id };};// Select a random item based on the probability of each optionfunction selectRandomReward(options) { if (!_.isArray(options)) { throw Error('Invalid daily reward options'); } let sumOfProbabilities = 0; options.forEach((option) => { sumOfProbabilities += option.probability; }); let random = _.random(0, sumOfProbabilities); for (let i = 0; i < options.length; i++) { if (random < options[i].probability) { return options[i]; } random -= options[i].probability; } throw Error('Unable to select a daily reward');}

Copyright © 2026 Unity Technologies
法規事項プライバシーポリシークッキーDocumentation Terms of Use私の個人情報を販売または共有しないプライバシーに関する選択 (クッキー設定)

"Unity" の名称、Unity のロゴ、およびその他の Unity の商標は、米国およびその他の国における Unity Technologies またはその関係会社の商標または登録商標です (詳しくはこちら)。その他の名称またはブランドは該当する所有者の商標です。

一部のページは利便性向上のため機械翻訳を使用しており、内容に不正確な表現が含まれる場合があります。内容に齟齬または不一致が生じた場合は、英語版を正本とします。

  • このページ
    • 設定

      • Economy

      • Remote Config

    • 1 日ごとのゲーム内報酬のスクリプト


このページの問題を報告する