RayValue
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
RayValue は、シングルレイを保存する目的で作成されたオブジェクトです。CFrameValue と同様、RayValue の保存されたレイはプロパティウィンドウ内の Studio の中で表示または編集できません。代わりに、コマンドバーを使用して、これらのオブジェクトの値
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) を使用して、レイを構造するために cf
すべての「-Value」オブジェクトと同様、この単一の値は「Value」プロパティに格納されます。変更されたイベントは、「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
概要
イベント
Class.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