# ClickDetector（ロブロックス クラス）

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

- URL：https://roblox.minecraft-okinawa.com/reference/classes/ClickDetector/
- 公式：https://create.roblox.com/docs/reference/engine/classes/ClickDetector
- 受け継いでいるクラス：Instance

## 使用例：クリックで開く扉

（Script／置く場所：扉にするパーツの中）

```lua
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／置く場所：パーツの中）

```lua
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)
```

## プロパティ

- `ClickDetector.CursorIcon: ContentId`：Sets the cursor icon to display when the mouse is hovered over the parent of this ClickDetector or DragDetector.
- `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.
- `ClickDetector.MaxActivationDistance: float`：クリックできる最大の距離。

## イベント

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

英語の説明とメンバー一覧：Roblox Creator Documentation（CC BY 4.0）。日本語の解説はこのサイト独自のものです。

執筆：鈴木孝昌（現役プロジェクトマネージャー／プログラミング講師）／運営：沖縄マイクラ部 プログラミングスクール「クロスウェーブ」（https://minecraft-okinawa.com/）