RayValue는 단일 광선을 저장하는 목적을 가진 개체입니다.CFRamValue와 마찬가지로 RayValue의 저장된 레이는 스튜디오 내의 속성 창에서 볼 수 없거나 편집할 수 없습니다.대신 명령 모음을 사용하여 이러한 개체의 값을 가져오고 설정합니다.예를 들어, 아래와 같은 줄을 사용하여 Workspace 내에 "값"이라는 새로운 RayValue를 생성할 수 있습니다.(0, 50, 0)에서 광선을 생성하고 양의 X 방향으로 향합니다.
Instance.new("RayValue").Value = Ray.new(Vector3.new(0, 50, 0), Vector3.new(10, 0, 0))
Studio에서 광선을 편집하는 간단한 방법은 없으므로 때로는 CFrameValue를 사용하는 것이 더 좋습니다(부품이나 카메라를 통해 변경할 수 있음).Ray.new(cf.p, cf.lookVector * dist) 에서 CFrame에서 광선을 재구성할 수 있으며, cf 는 지정된 CFrame이고 dist 는 생성하려는 광선의 길이입니다.
모든 "-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 속성이 발생합니다.속성이 변경되는 문자열 대신 새 값이 인수 개체에 저장되어 실행됩니다. It will run with the new value being stored in the argument object, instead of a string representing the property being changed.
이 이벤트는 다른 변경된 이벤트와 마찬가지로 변경 시기를 추적하고 변경될 수 있는 다양한 값을 추적하는 데 사용할 수 있습니다.
요구 사항에 가장 적합한 개체 유형에 따라 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