Seat

显示已弃用

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

玩家角色可以“坐”在的BasePart类型。当角色触碰启用的座位对象时,将由 Weld 附加到零件上,默认角色脚本将播放坐姿动画。

座位如何工作?

当含有 HumanoidBasePart 的模型调用 'HumanoidRootPart' (通常是玩家角色) 时,座椅与零件之间会创建一个 WeldC0C1 属性配置为将角色焊在座椅上方 2 个螺柱。该焊接被命名为“座椅焊接”,并作为座椅的父级。

当坐下时,Seat.Occupant 属性设置为坐在座位上的 Humanoid 。此外,人形的 Humanoid.SeatPart 属性设置为座位。

一个角色也可以被强迫坐在座位上使用 Seat:Sit() 函数。

有两种方法可以让角色离开座位。当玩家跳跃时,他们将被从座位上移除。但是,也可以手动完成,例如通过摧毁座椅接合来实现:

座椅:FindFirstChild("座椅焊接":破坏()

注意座位有一个冷却时间(目前为 3 秒),这是基于每个角色每个座位的。这意味着一旦角色从座位上离开,他们不能在同一座位上坐下 3 秒。这种冷却行为可能会改变,开发人员不应该依赖它。

座位可以用于什么?

座椅有很多用途,从显而易见到更不寻常。

  • 无需编程即可创建椅子或凳子
  • 允许角色在移动对象,例如车辆,上“坐下”而不被扔出
  • 使用 Seat.Occupant 属性控制座椅中角色控制的接口创建

代码示例

This code sample includes a demonstration of how the Seat.Occupant property can be used to track which player is sitting in a seat and when they sit down or sit up.

Detecting Seat Occupant

local Players = game:GetService("Players")
local seat = Instance.new("Seat")
seat.Anchored = true
seat.Position = Vector3.new(0, 1, 0)
seat.Parent = workspace
local currentPlayer = nil
local function onOccupantChanged()
local humanoid = seat.Occupant
if humanoid then
local character = humanoid.Parent
local player = Players:GetPlayerFromCharacter(character)
if player then
print(player.Name .. " has sat down")
currentPlayer = player
return
end
end
if currentPlayer then
print(currentPlayer.Name .. " has got up")
currentPlayer = nil
end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(onOccupantChanged)

概要

属性

  • 读取并联

    座椅是否可用。如果设置为真,座椅将作为普通部件运行。

  • 只读
    未复制
    读取并联

    坐在座位上的人形。

继承自Part属性继承自BasePart属性继承自PVInstance属性

方法

继承自BasePart方法继承自PVInstance方法
  • 写入并联

    获取 PVInstance 的枢轴。

  • PivotTo(targetCFrame : CFrame):()

    将 以及所有其子孙 转换为位于指定 的位置,使旋转点现在位于指定的 。

活动

继承自BasePart活动

属性

Disabled

读取并联

座椅是否可用。如果设置为真,座椅将作为普通部件运行。

Occupant

只读
未复制
读取并联

坐在座位上的人形怪物

方法

Sit

()

强制具有指定 Humanoid 的角色坐在座位上。

参数

humanoid: Instance
默认值:""

返回

()

活动