Dialog

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

对话对象允许用户创建非玩家角色(NPC),玩家可以使用一个列表与其进行交谈。对话对象可以插入到像人形的头部等部件中,然后玩家会看到一个上面的对话泡泡,可以单击以开始对话。地点的创建者可以通过插入 DialogChoice 对象来选择玩家可以说的选择。

概要

属性

方法

活动

属性

读取并联

对话框的行为类型决定了多个玩家是否可以一次与对话框交互。该属性的默认值为单人玩家。

单人玩家

当对话配置为单个玩家时,只有一个玩家可以一次与其交互。一旦玩家与对话框交互,其他玩家将无法启动对话框,直到第一个玩家完成为止。

当玩家与对话框交互时,其他玩家会看到启动对话框的玩家的对话选项以及回应。

多个玩家

当对话设置为多个玩家时,任何玩家都可以随时启动对话,即使另一名玩家已经启动了对话。但与单人玩家不同,设置为多人玩家的对话不会向任何人显示对话选项和回应,只向对话中的玩家显示。


local Workspace = game:GetService("Workspace")
local singlePlayerDialog = Instance.new("Dialog")
local singlePlayerPart = Workspace.SinglePlayerPart
singlePlayerDialog.BehaviorType = Enum.DialogBehaviorType.SinglePlayer
singlePlayerDialog.InitialPrompt = "Only one person can interact with me at once."
singlePlayerDialog.Parent = singlePlayerPart
local multiplePlayersDialog = Instance.new("Dialog")
local multiplePlayersPart = Workspace.MultiplePlayersPart
multiplePlayersDialog.BehaviorType = Enum.DialogBehaviorType.MultiplePlayers
multiplePlayersDialog.InitialPrompt = "Any number of players can interact with me at once."
multiplePlayersDialog.Parent = multiplePlayersPart

ConversationDistance

读取并联

玩家从对话父辈最远的距离,可以开始对话。

GoodbyeChoiceActive

读取并联

切换是否显示再见选项。如果真实,对话框将显示 Dialog.GoodbyeDialog 内容作为其他对话框选择后的最后一个选项。单击再见选项将退出对话框。

GoodbyeDialog

读取并联

设置对话框在聊天结束时向玩家显示的句子

InUse

读取并联

如果真实,该对话框至少被一个玩家使用。

InitialPrompt

读取并联

设置对话框将向玩家显示的第一句话,一旦聊天开始后。

读取并联

设置初始对话框显示的图标。

读取并联

设置 NPC 的对话泡泡颜色。

TriggerDistance

读取并联

设置对话框可触发的最大距离。

TriggerOffset

读取并联

设置对话框与对话父父元素的偏移。

方法

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 实例发射。

该事件仅由客户端发起,不会在服务器上发射。它应该连接到在 LocalScriptModuleScriptLocalScript 要求的任何一个。

参数

player: Instance
dialogChoice: Instance