ProximityPromptクラス
ひとことで言うと
パーツに近づくと「Eキーで調べる」のような表示が出て、ボタンを押すと処理を実行できる部品です。
公式の説明(英語):An object that lets you prompt players to interact with an object in the 3D world.
使用例
local part = script.Parent :: BasePart
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = "ひらく"
prompt.ObjectText = "宝箱"
prompt.Parent = part
prompt.Triggered:Connect(function(player)
print(player.Name .. " が宝箱をひらいた!")
part.BrickColor = BrickColor.new("Bright yellow")
end)スクリプトは、Luauの型チェック(luau-lsp)で確認しています。
クラスの関係
プロパティ(15)
| 名前と書き方 | 説明 |
|---|---|
ActionTextProximityPrompt.ActionText: string | ボタンに表示する行動の文字(例:ひらく)。The action text shown to the user. |
AutoLocalizeProximityPrompt.AutoLocalize: boolean | Whether the prompt's ProximityPrompt.ActionText and ProximityPrompt.ObjectText will be localized according to the ProximityPrompt.RootLocalizationTable. |
ClickablePromptProximityPrompt.ClickablePrompt: boolean | Whether the prompt can be activated by clicking/tapping on the prompt UI. |
EnabledProximityPrompt.Enabled: boolean | Whether or not this prompt should be shown. |
ExclusivityProximityPrompt.Exclusivity: ProximityPromptExclusivity | Used to customize which prompts can be shown at the same time. |
GamepadKeyCodeProximityPrompt.GamepadKeyCode: KeyCode | The gamepad button the player should press to trigger the prompt. |
HoldDurationProximityPrompt.HoldDuration: float | ボタンを長押しする必要がある秒数。The duration, in seconds, that the player must hold the button/key down to trigger the prompt. |
KeyboardKeyCodeProximityPrompt.KeyboardKeyCode: KeyCode | 使うキー。初期値はEキーです。The key the player should press to trigger the prompt. |
MaxActivationDistanceProximityPrompt.MaxActivationDistance: float | 表示される最大の距離。The maximum distance a Player's Class.Player.Character|character can be from the ProximityPrompt for the prompt to appear. |
MaxIndicatorDistanceProximityPrompt.MaxIndicatorDistance: float | The maximum distance at which a lightweight indicator for the prompt is shown, hinting at a nearby interaction before the player is close enough to trigger it. |
ObjectTextProximityPrompt.ObjectText: string | 対象の名前の文字(例:宝箱)。An optional property that determines the object name text shown to the user. |
RequiresLineOfSightProximityPrompt.RequiresLineOfSight: boolean | Whether the prompt is hidden if the path between the player's Camera and object parented to the ProximityPrompt is obstructed. |
RootLocalizationTableProximityPrompt.RootLocalizationTable: LocalizationTable | A reference to a LocalizationTable to be used to apply automated localization to this prompt's ProximityPrompt.ActionText and ProximityPrompt.ObjectText. |
StyleProximityPrompt.Style: ProximityPromptStyle | The style of the prompt's UI. |
UIOffsetProximityPrompt.UIOffset: Vector2 | The pixel offset applied to the prompt's UI. |
メソッド(2)
| 名前と書き方 | 説明 |
|---|---|
InputHoldBeginProximityPrompt:InputHoldBegin(): () | Fires a signal indicating that the user began pressing the prompt GUI button. |
InputHoldEndProximityPrompt:InputHoldEnd(): () | Fires a signal indicating that the user ended pressing the prompt GUI button. |
イベント(8)
| 名前と書き方 | 説明 |
|---|---|
IndicatorHiddenProximityPrompt.IndicatorHidden() | Fires on the client when a lightweight indicator for the prompt is no longer shown. |
IndicatorShownProximityPrompt.IndicatorShown() | Fires on the client when a lightweight indicator for the prompt becomes visible. |
PromptButtonHoldBeganProximityPrompt.PromptButtonHoldBegan(playerWhoTriggered: Player) | Triggered when a player begins holding down the Class.ProximityPrompt.KeyboardKeyCode|key/button connected to a prompt with a non-zero ProximityPrompt.HoldDuration. |
PromptButtonHoldEndedProximityPrompt.PromptButtonHoldEnded(playerWhoTriggered: Player) | Triggers when the player ends holding down the button on a prompt with a non-zero ProximityPrompt.HoldDuration. |
PromptHiddenProximityPrompt.PromptHidden() | Triggers when the Class.ProximityPrompt|prompt becomes hidden. |
PromptShownProximityPrompt.PromptShown(inputType: ProximityPromptInputType) | Triggers when the Class.ProximityPrompt|prompt becomes visible. |
TriggeredProximityPrompt.Triggered(playerWhoTriggered: Player) | プレイヤーがボタンを押したときに発生するイベントです。Triggered when the prompt Class.ProximityPrompt.KeyboardKeyCode|key/button is pressed, or after a specified amount of time holding the button, if ProximityPrompt.HoldDuration is used. |
TriggerEndedProximityPrompt.TriggerEnded(playerWhoTriggered: Player) | Triggers when Class.ProximityPrompt.KeyboardKeyCode|key/button is released, for longer events where the user is required to hold down the button. |
受け継いでいるメンバー
Instance から受け継いでいるもの(46)
Archivable・Capabilities・IsInSandbox・Name・Parent・PredictionMode・Sandboxed・AddTag・ClearAllChildren・Clone・Destroy・FindFirstAncestor・FindFirstAncestorOfClass・FindFirstAncestorWhichIsA・FindFirstChild・FindFirstChildOfClass・FindFirstChildWhichIsA・FindFirstDescendant・GetActor・GetAttribute・GetAttributeChangedSignal・GetAttributes・GetChildren・GetDebugId・GetDescendants・GetFullName・GetStyled・GetStyledPropertyChangedSignal・GetTags・HasTag・IsAncestorOf・IsDescendantOf・IsPropertyModified・QueryDescendants・RemoveTag・ResetPropertyToDefault・SetAttribute・WaitForChild・AncestryChanged・AttributeChanged・ChildAdded・ChildRemoved・DescendantAdded・DescendantRemoving・Destroying・StyledPropertiesChanged
Object から受け継いでいるもの(4)
ProximityPromptを使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(ProximityPrompt)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。