RayValue
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
RayValue เป็นวัตถุที่มีไว้เพื่อเก็บเลเซอร์เดียว ใกล้เคียงกับ CFrameValue รัศมีของเลเซอร์ที่เก็บไว้ของ RayValue จะไม่สามารถดูหรือแก้ไขได
Instance.new("RayValue").Value = Ray.new(Vector3.new(0, 50, 0), Vector3.new(10, 0, 0))
เนื่องจากไม่มีวิธีง่ายๆในการแก้ไขรังสีภายใน Studio ดังนั้นจึงดีกว่าที่จะใช้ CFrameValue แทน (ซึ่งสามารถเปลี่ยนผ่านส่วนหรือกล้อง) คุณสา
เหมือนวัตถุ “-Value” อื่น ๆ เดียวกันนี้มีมูลค่าเดียวที่เก็บไว้ในสมบัติสมบัติ เหตุการณ์ที่เปลี่ยนแปลงสำหรับสิ่งนี้ (และวัตถุอื่น ๆ เช่นมัน) จะเริ่มต้นด้วยมูลค่าที่เก็บไว้ในสมบัติ
ตัวอย่างโค้ด
This code sample demonstrates constructing a Ray, storing the Ray within a RayValue and Raycasting to find other parts between two parts named "PartA" and "PartB".
local partA = workspace.PartA
local partB = workspace.PartB
local origin = partA.Position
local direction = partB.Position - partA.Position
local ray = Ray.new(origin, direction)
local rayValue = Instance.new("RayValue")
rayValue.Value = ray
rayValue.Name = "PartA-to-PartB Ray"
rayValue.Parent = workspace
-- Raycast to find any parts in between PartA and PartB
local part = workspace:FindPartOnRay(ray)
if part then
print("Hit part: " .. part:GetFullName())
else
-- This ought to never happen, as our ray starts at PartA
-- and points towards PartB, so we should always hit PartB
-- or some other part.
print("No part hit!")
end
สรุป
อีเวนต์
ไฟร์เมื่อ RayValue.Value เปลี่ยนแปลง
คุณสมบัติ
วิธีการ
อีเวนต์
Changed
เหตุการณ์นี้จะเกิดขึ้นเมื่อสมบัติสมบัติ RayValue.Value ถูกเปลี่ยนแปลง มันจะทำงานร่วมกับค่าใหม่ที่เก็บไว้ในตัวอาร์กิวเมนต์ แทนที่จะเป็นสตริงที่แทนที่สถานะการเปลี่ยนแปลง
กิจกรรมนี้เหมือนกิจกรรมอื่น ๆ สามารถใช้เพื่อติดตามเมื่อ RayValue เปลี่ยนและติดตามมูลค่าที่แตกต่างกันที่มันอาจเปลี่ยน
มีเหตุการณ์ที่เทียบเท่ากันสำหรับวัตถุที่คล้ายคลึงกันเช่น NumberValue และ StringValue ตามประเภทของวัตถุที่เหมาะกับความต้องการมากที่สุด
พารามิเตอร์
มูลค่าหลังการเปลี่ยนแปลง
ตัวอย่างโค้ด
The below example, assuming all referenced objects existed, would print the RayValue's new value each time it changed. In the example below it would print "{0, 0, 0}, {0.577350199, 0.577350199, 0.577350199}".
local value = Instance.new("RayValue")
value.Parent = workspace
value.Changed:Connect(function(NewValue)
print(NewValue)
end)
local start = Vector3.new(0, 0, 0)
local lookAt = Vector3.new(10, 10, 10)
local ray = Ray.new(start, (lookAt - start).Unit)
value.Value = ray