Vector3Value

Hiển Thị Bản Đã Lỗi Thời

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.

Một Vector3Value chỉ giữ một Vector3 như một giá trị. Giá trị này có thể được sử dụng cho các kịch bản để giao tiếp, cho các đối tượng di chuyển đến một vị trí cố định, v.v.

Mẫu mã

This code sample causes a Part to teleport any players that touch it to a specific position defined by a "TeleportPosition" Vector3Value.

Teleporter Part

-- Paste me in a Script inside a Part
local part = script.Parent
local teleportPosition = part.TeleportPosition
local function onTouch(otherPart)
-- First, find the HumanoidRootPart. If we can't find it, exit.
local hrp = otherPart.Parent:FindFirstChild("HumanoidRootPart")
if not hrp then
return
end
-- Now teleport by setting the CFrame to one created from
-- the stored TeleportPosition
hrp.CFrame = CFrame.new(teleportPosition.Value)
end
part.Touched:Connect(onTouch)

This code sample demonstrates how it is possible to store a Vector2 within a Vector3Value by converting a Vector2 into a Vector3 with a dummy Z value. Similarly, you can load it by reconstructing the Vector2 from the X and Y axes.

Storing Vector2 inside Vector3Value

local vector3Value = Instance.new("Vector3Value")
-- Store a Vector2 in a Vector3
local vector2 = Vector2.new(42, 70)
vector3Value.Value = Vector3.new(vector2.X, vector2.Y, 0) -- The Z value is ignored
-- Load a Vector2 from a Vector3
vector2 = Vector2.new(vector3Value.Value.X, vector3Value.Value.Y)
print(vector2)

Thuộc Tính

Value

Đọc Song Song

Các được lưu Vector3 .

Phương Pháp

Sự Kiện

Changed

Bị sa thải bất cứ khi nào Vector3Value.Value của Vector3Value được thay đổi.Nó sẽ chạy với giá trị mới được lưu trong đối tượng argument, thay vì một chuỗi đại diện cho thuộc tính đang thay đổi.

Sự kiện này, giống như các sự kiện thay đổi khác, có thể được sử dụng để theo dõi khi một Vector3Value thay đổi và theo dõi các giá trị khác nhau có thể thay đổi.

Ví ví dụ / trường hợp, nó có thể hữu ích trong các trò chơi dựa vào Vector3Values để theo dõi vị trí trong thế giới trò chơi.

Các sự kiện thay đổi tương đương tồn tại cho các đối tượng tương tự, chẳng hạn như NumberValueStringValue , tùy thuộc vào loại đối tượng nào phù hợp nhất với nhu cầu.

Tham Số

value: Vector3

Giá trị mới sau khi thay đổi.


Mẫu mã

The below example, assuming all referenced objects existed, would print the Vector3Value's new value each time it changed. In the example below it would print "10,10,10".

How to Use Vector3Value.Changed

local value = Instance.new("Vector3Value")
value.Parent = workspace
value.Changed:Connect(function(NewValue)
print(NewValue)
end)
value.Value = Vector3.new(10, 10, 10)