このステップでは、プレイヤーが命中すると追加時間を与える特別なターゲットを作成します。 このターゲットは、プラスのスコアを持つターゲットに命中した際にランダムでポップアップし、出現するまで確率が徐々に上がっていきます。
島を編集する
ビューポートで [コンボターゲット] を選択します。
Alt キーを押しながら軸ウィジェットを左クリックし、複製したターゲットを射撃ギャラリーの手前にドラッグします。 これがボーナス タイム ターゲットです。
[詳細] パネルで TargetType を [Dancing] に設定します。
Verse コードを書く
このページでは、コード変更をステップごとに案内します。作業内容を確認したい場合は、最終結果として「完全なコード」セクションを参照してください。
shooting_range_manager_device.verseファイルを開きます。乱数生成をサポートするためのライブラリを追加します。
Verseusing { /Verse.org/Random }ターゲットの仕掛けの参照および関連プロパティを格納する変数を追加します。 時間の長さと報酬の変数は秒単位です。
Verse@editable InitialTimerDuration:float = 30.0 @editable MaxTimerDuration:float = 60.0 @editable BonusTimeTarget:shooting_range_target_track_device = shooting_range_target_track_device{} @editableタイマーを増加させる
OnBonusTimeTargetHitコールバック メソッドを追加します。Verse# A hit callback that adds bonus time and disables the BonusTimeTarget. OnBonusTimeTargetHit():void= CurrentDuration:float = Timer.GetActiveDuration() Timer.SetActiveDuration(CurrentDuration + BonusTimeReward) BonusTimeTarget.PopDown() BonusTimeTarget.Disable()OnBeginメソッドを修正し、ボーナス タイム ターゲットのイベント サブスクリプションを設定して無効化します。Verse# Runs when the device is started in a running game. OnBegin<override>()<suspends>:void= # Subscribing to the GoodTarget HitEvents. GoodTarget1.HitEvent.Subscribe(OnGoodTarget1Hit) GoodTarget2.HitEvent.Subscribe(OnGoodTarget2Hit) GoodTarget3.HitEvent.Subscribe(OnGoodTarget3Hit) # Subscribing to the BadTarget HitEvents. BadTarget1.HitEvent.Subscribe(OnBadTarget1Hit) BadTarget2.HitEvent.Subscribe(OnBadTarget2Hit)StartTimerメソッドを修正し、タイマーの最大時間とアクティブ時間を設定します。Verse# Setup and start the timer. StartTimer():void= # Set the event subscription to call OnTimerSuccess when the timer finishes. Timer.SuccessEvent.Subscribe(OnTimerSuccess) <# --- New Code Start --- #> # Set the max and active duration based on the set property values. Timer.SetMaxDuration(MaxTimerDuration) Timer.SetActiveDuration(InitialTimerDuration)AdjustScoreメソッドを修正し、命中した GootTarget の数に基づいてボーナスタイム ターゲットがランダムに出現するようにします。Verse# Adjusts the player's score by the provided value. AdjustScore(Value:int):void= # Start the timer if it hasn't started yet. if (not IsTimerStarted?): StartTimer() # Sets the score award to the base value of the target. ScoreManager.SetScoreAward(Value) # Gets the first player in the playspace.Verse コードを保存してビルドします。
完全なコード
using { /Fortnite.com/Devices }
using { /Verse.org/Random }
using { /Verse.org/Simulation }
# A device that manages shooting range gameplay.
shooting_range_manager_device := class(creative_device):
@editable
ScoreManager:score_manager_device = score_manager_device{}
まとめ
ビューポートまたは [アウトライナー] パネルで shooting_range_manager_device を選択します。
[詳細] パネルで、BonusTimeTarget をボーナス タイム ターゲットに設定します。
変更をプッシュして島をプレイテストします。
プラスのスコアを与えるターゲットを撃った後、ボーナス タイム ターゲットが時々出現することを確認します。