Vector3Value
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
Vector3Value เป็นตัวแปรงที่มี Vector3 เป็นค่า
ตัวอย่างโค้ด
This code sample causes a Part to teleport any players that touch it to a specific position defined by a "TeleportPosition" Vector3Value.
-- 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.
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)
คุณสมบัติ
วิธีการ
อีเวนต์
Changed
เปิดใช้งานเมื่อ Vector3Value.Value ของ Vector3Value เปลี่ยนแปลง มันจะทำงานด้วยค่าใหม่ที่เก็บไว้ในตัวอาร์กิวเมนต์แทนที่จะเป็นสตริงที่แทนที่สถานะการเปลี่ยนแปลง
เหตุการณ์นี้เหมือนเหตุการณ์อื่น ๆ สามารถใช้เพื่อติดตามเมื่อVector3Valueเปลี่ยนและติดตามค่าที่แตกต่างกันที่มันอาจเปลี่ยน
อินสแตนซ์นี่อาจเป็นประโยชน์ในเกมที่ใช้ Vector3Values เพื่อติดตามตำแหน่งในโลกเกม
มีเหตุการณ์ที่เทียบเท่ากันสำหรับวัตถุที่คล้ายคลึงกันเช่น NumberValue และ StringValue ตามประเภทของวัตถุที่เหมาะกับความต้องการมากที่สุด
พารามิเตอร์
มูลค่าใหม่หลังการเปลี่ยนแปลง
ตัวอย่างโค้ด
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".
local value = Instance.new("Vector3Value")
value.Parent = workspace
value.Changed:Connect(function(NewValue)
print(NewValue)
end)
value.Value = Vector3.new(10, 10, 10)