ProximityPromptクラス

クラス日本語解説あり

ひとことで言うと

パーツに近づくと「Eキーで調べる」のような表示が出て、ボタンを押すと処理を実行できる部品です。

公式の説明(英語):An object that lets you prompt players to interact with an object in the 3D world.

使用例

近づいて宝箱をひらく
Script置く場所:宝箱にするパーツの中
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)で確認しています。

クラスの関係

受け継いでいるクラス:Object → Instance → ProximityPrompt

プロパティ(15)

名前と書き方説明
ActionText
ProximityPrompt.ActionText: string
ボタンに表示する行動の文字(例:ひらく)。The action text shown to the user.
AutoLocalize
ProximityPrompt.AutoLocalize: boolean
Whether the prompt's ProximityPrompt.ActionText and ProximityPrompt.ObjectText will be localized according to the ProximityPrompt.RootLocalizationTable.
ClickablePrompt
ProximityPrompt.ClickablePrompt: boolean
Whether the prompt can be activated by clicking/tapping on the prompt UI.
Enabled
ProximityPrompt.Enabled: boolean
Whether or not this prompt should be shown.
Exclusivity
ProximityPrompt.Exclusivity: ProximityPromptExclusivity
Used to customize which prompts can be shown at the same time.
GamepadKeyCode
ProximityPrompt.GamepadKeyCode: KeyCode
The gamepad button the player should press to trigger the prompt.
HoldDuration
ProximityPrompt.HoldDuration: float
ボタンを長押しする必要がある秒数。The duration, in seconds, that the player must hold the button/key down to trigger the prompt.
KeyboardKeyCode
ProximityPrompt.KeyboardKeyCode: KeyCode
使うキー。初期値はEキーです。The key the player should press to trigger the prompt.
MaxActivationDistance
ProximityPrompt.MaxActivationDistance: float
表示される最大の距離。The maximum distance a Player's Class.Player.Character|character can be from the ProximityPrompt for the prompt to appear.
MaxIndicatorDistance
ProximityPrompt.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.
ObjectText
ProximityPrompt.ObjectText: string
対象の名前の文字(例:宝箱)。An optional property that determines the object name text shown to the user.
RequiresLineOfSight
ProximityPrompt.RequiresLineOfSight: boolean
Whether the prompt is hidden if the path between the player's Camera and object parented to the ProximityPrompt is obstructed.
RootLocalizationTable
ProximityPrompt.RootLocalizationTable: LocalizationTable
A reference to a LocalizationTable to be used to apply automated localization to this prompt's ProximityPrompt.ActionText and ProximityPrompt.ObjectText.
Style
ProximityPrompt.Style: ProximityPromptStyle
The style of the prompt's UI.
UIOffset
ProximityPrompt.UIOffset: Vector2
The pixel offset applied to the prompt's UI.

メソッド(2)

名前と書き方説明
InputHoldBegin
ProximityPrompt:InputHoldBegin(): ()
Fires a signal indicating that the user began pressing the prompt GUI button.
InputHoldEnd
ProximityPrompt:InputHoldEnd(): ()
Fires a signal indicating that the user ended pressing the prompt GUI button.

イベント(8)

名前と書き方説明
IndicatorHidden
ProximityPrompt.IndicatorHidden()
Fires on the client when a lightweight indicator for the prompt is no longer shown.
IndicatorShown
ProximityPrompt.IndicatorShown()
Fires on the client when a lightweight indicator for the prompt becomes visible.
PromptButtonHoldBegan
ProximityPrompt.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.
PromptButtonHoldEnded
ProximityPrompt.PromptButtonHoldEnded(playerWhoTriggered: Player)
Triggers when the player ends holding down the button on a prompt with a non-zero ProximityPrompt.HoldDuration.
PromptHidden
ProximityPrompt.PromptHidden()
Triggers when the Class.ProximityPrompt|prompt becomes hidden.
PromptShown
ProximityPrompt.PromptShown(inputType: ProximityPromptInputType)
Triggers when the Class.ProximityPrompt|prompt becomes visible.
Triggered
ProximityPrompt.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.
TriggerEnded
ProximityPrompt.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)

ClassName・GetPropertyChangedSignal・IsA・Changed

ProximityPromptを使う記事

英語の説明とメンバーの一覧は、Roblox Creator Documentation(ProximityPrompt)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。

執筆:鈴木孝昌官公庁のWeb・システム開発を担当する現役プロジェクトマネージャー。沖縄マイクラ部 クロスウェーブで、ロブロックス(Roblox)・マインクラフト(マイクラ)・Scratchなどのプログラミングを指導。マイクラカップ沖縄代表チームを指導(第6回・第7回、第7回TBS賞)。
沖縄マイクラ部で、子どもたちにロブロックス(Roblox)やマインクラフト(マイクラ)のプログラミングを教えています。プロフィールと編集方針
Instagramで教室の様子を見る
noteで記事を読む