對話對象允許使用者創建非玩家角色(NPC),玩家可以使用一個選擇列表與其進行對話。對話對象可以插入到像人形的頭部等零件中,然後玩家會看到上面有一個對話泡泡,他們可以單擊以開始對話。位置的創建者可以通過插入 DialogChoice 物件來選擇玩家可以說的選擇。
概要
屬性
設置對話框是否可以一次由多名玩家使用。
玩家可以從對話的父處到最遠的距離開始對話。
切換是否顯示再見選項。
設置對話框在聊天結束時顯示給玩家的句子。
如果真實,這個對話框被至少一名玩家使用。
設置對話框會向玩家顯示的第一句話,一旦聊天開始。
設置初始對話框顯示的圖示。
設置 NPC 的對話泡泡的顏色。
設置對話框可以被觸發的最大距離。
設置對話框與對話框父元素親的偏移。
活動
當玩家選擇說話時,通過 Dialog 實個體、實例發射。
屬性
BehaviorType
對話框的行為類型決定是否多名玩家可以一次與對話框互動。此特性的預設值為單人玩家。
單人玩家
當對話配置為單一玩家時,只有一名玩家可以一次與它互動。一旦玩家與對話框互動,其他玩家將無法在第一位玩家完成之前啟動對話框。
當玩家與對話框互動時,其他玩家會看到啟動對話的玩家的對話選項以及回應。
多個玩家
當對話設為多個玩家時,任何玩家都可以隨時啟動對話,即使另一名玩家已經啟動了對話。但與單人玩家不同,設為多人玩家的對話框不會向任何人顯示對話選項和回應,只有對話中的玩家可以看到。
local Workspace = game:GetService("Workspace")local singlePlayerDialog = Instance.new("Dialog")local singlePlayerPart = Workspace.SinglePlayerPartsinglePlayerDialog.BehaviorType = Enum.DialogBehaviorType.SinglePlayersinglePlayerDialog.InitialPrompt = "Only one person can interact with me at once."singlePlayerDialog.Parent = singlePlayerPartlocal multiplePlayersDialog = Instance.new("Dialog")local multiplePlayersPart = Workspace.MultiplePlayersPartmultiplePlayersDialog.BehaviorType = Enum.DialogBehaviorType.MultiplePlayersmultiplePlayersDialog.InitialPrompt = "Any number of players can interact with me at once."multiplePlayersDialog.Parent = multiplePlayersPart
方法
GetCurrentPlayers
Instances
對話框的 GetCurrentPlayers 功能將返回一個列表,其中包含 Player 目前正在使用對話框的玩家。如果沒有使用對話框的玩家,則返回的列表將為空。
返回
Instances
範例程式碼
Dialog:GetCurrentPlayers
local dialog = script.Parent
local function onChoiceSelected(_player, _choice)
local currentPlayers = dialog:GetCurrentPlayers()
print("The current players in the dialog:")
for _, player in ipairs(currentPlayers) do
print(player)
end
end
dialog.DialogChoiceSelected:Connect(onChoiceSelected)
活動
DialogChoiceSelected
當玩家選擇說話時,通過 Dialog 實個體、實例發射。
這個事件只是客戶端,不會在伺服器上發射。它應該連接到 LocalScript 或 ModuleScript 由 LocalScript 要求的任何一個。