Vector3Value

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

Vector3Value は単に Vector3 を値として保持します。この値は、スクリプトでコミュニケーションする、オブジェクトをプリセットの場所に移動するなど、用途に使用できます。

コードサンプル

This code sample causes a Part to teleport any players that touch it to a specific position defined by a "TeleportPosition" Vector3Value.

Teleporter Part

-- 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.

Storing Vector2 inside Vector3Value

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)

プロパティ

Value

並列読み取り

保存された Vector3

方法

イベント

Changed

発射されるのは、Vector3Value.ValueVector3Value が変更されたときです。新しい値が引数オブジェクトに保存される代わりに、変更されるプロパティを表すストリングではなく、新しい値が引数オブジェクトで実行されます。

このイベントは、他の変更されたイベントと同様、ベクトル3値が変更された時間を追跡し、変更される可能性のある異なる値を追跡することができます。

たとえば、ゲーム世界での位置を追跡するために Vector3Values に依存するゲームでは、これが役に立つかもしれません。

同等の変更イベントは、NumberValueStringValue など、必要に最適なオブジェクトタイプによって異なります。

パラメータ

value: Vector3

変更後の新しい値。


コードサンプル

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".

How to Use Vector3Value.Changed

local value = Instance.new("Vector3Value")
value.Parent = workspace
value.Changed:Connect(function(NewValue)
print(NewValue)
end)
value.Value = Vector3.new(10, 10, 10)