Seat

顯示已棄用項目

*此內容是使用 AI(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
預設值:""

返回

()

活動