RayValue
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
レイバリューは、単一のレイを保存する目的のあるオブジェクトです。CFRAMEValueと同様、レイバリューの保存されたレイは、スタジオ内のプロパティウィンドウ内で表示または編集することはできません。代わりに、コマンドバーを使用して、これらのオブジェクトの値を取得し、設定します。たとえば、下のようなラインを使用して、 Workspace 内で新しい RayValue 「Value」を作成できます。(0, 50, 0) で線を作成し、正方向 X に面します。
Instance.new("RayValue").Value = Ray.new(Vector3.new(0, 50, 0), Vector3.new(10, 0, 0))
Studio 内で線を編集する簡単な方法はないので、時々 CFrameValue を使用する方が良い (これはパーツまたはカメラを通じて変更できます)。You can reconstruct a ray from a CFrame using Ray.new(cf.p, cf.lookVector * dist) , where 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 プロパティが変更されるたびに発動します。新しい値が引数オブジェクトに保存される代わりに、変更されるプロパティを表すストリングではなく、新しい値が引数オブジェクトで実行されます。
このイベントは、他の変更されたイベントと同様、レイバル値が変更された時間を追跡し、変更される可能性のある異なる値を追跡することができます。
同等の変更イベントは、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