ClickDetectorクラス

クラス日本語解説あり

ひとことで言うと

パーツの中に入れると、そのパーツをマウスでクリックできるようにする部品です。

公式の説明(英語):An object that provides user input on in-experience Class.BasePart|BaseParts and Class.Model|Models.

使用例

クリックで開く扉
Script置く場所:扉にするパーツの中
local door = script.Parent :: BasePart
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = door
local isOpen = false

clickDetector.MouseClick:Connect(function(player)
	isOpen = not isOpen
	door.Transparency = if isOpen then 0.8 else 0
	door.CanCollide = not isOpen
end)
クリックで色が変わるパーツ
Script置く場所:パーツの中
local part = script.Parent :: BasePart
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part

clickDetector.MouseClick:Connect(function()
	part.Color = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))
end)

スクリプトは、Luauの型チェック(luau-lsp)で確認しています。

クラスの関係

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

このクラスを受け継ぐクラス:DragDetector

プロパティ(3)

名前と書き方説明
CursorIcon
ClickDetector.CursorIcon: ContentId
Sets the cursor icon to display when the mouse is hovered over the parent of this ClickDetector or DragDetector.
CursorIconContent
ClickDetector.CursorIconContent: Content
Sets the cursor icon to display when the mouse is hovered over the parent of this ClickDetector or DragDetector. Only supports asset URIs.
MaxActivationDistance
ClickDetector.MaxActivationDistance: float
クリックできる最大の距離。Maximum distance between a character and the ClickDetector or DragDetector for the player to be able to interact with it.

イベント(4)

名前と書き方説明
MouseClick
ClickDetector.MouseClick(playerWhoClicked: Player)
パーツがクリックされたときに発生するイベントです。クリックしたプレイヤーが渡されます。Fires when a player interacts with the parent of a ClickDetector or DragDetector.
MouseHoverEnter
ClickDetector.MouseHoverEnter(playerWhoHovered: Player)
Fires when the parent of a ClickDetector or DragDetector is hovered over by a player.
MouseHoverLeave
ClickDetector.MouseHoverLeave(playerWhoHovered: Player)
Fires when a player's cursor hovers off the parent of a ClickDetector or DragDetector.
RightMouseClick
ClickDetector.RightMouseClick(playerWhoClicked: Player)
Fires when a player right clicks their mouse cursor on a ClickDetector or DragDetector.

受け継いでいるメンバー

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

ClickDetectorを使う記事

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

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