对话对象允许用户创建非玩家角色(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
对话框的获取当前玩家函数将返回一个列表,其中包含 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 要求的任何一个。