3D 向量和点的表示。
此结构在 Unity 中用于传递 3D 位置和方向。它还包含用于执行常见向量运算的函数。
除了下面列出的函数外,其他类也可以用于操作向量和点。例如,Quaternion 和 Matrix4x4 类可用于旋转或变换向量和点。
back | 编写 Vector3(0, 0, -1) 的简写。 |
down | 编写 Vector3(0, -1, 0) 的简写。 |
forward | 编写 Vector3(0, 0, 1) 的简写。 |
left | 编写 Vector3(-1, 0, 0) 的简写。 |
negativeInfinity | 编写 Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity) 的简写。 |
one | 编写 Vector3(1, 1, 1) 的简写。 |
positiveInfinity | 编写 Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity) 的简写。 |
right | 编写 Vector3(1, 0, 0) 的简写。 |
up | 编写 Vector3(0, 1, 0) 的简写。 |
zero | 编写 Vector3(0, 0, 0) 的简写。 |
magnitude | 返回此向量的长度(只读)。 |
normalized | 基于当前向量返回一个标准化向量。标准化向量的长度为 1,并且与当前向量方向相同。如果当前向量太小而无法标准化,则返回零向量。 |
sqrMagnitude | 返回此向量的平方长度(只读)。 |
this[int] | 分别使用 [0]、[1]、[2] 访问 x、y、z 分量。 |
x | 向量的 X 分量。 |
y | 向量的 Y 分量。 |
z | 向量的 Z 分量。 |
Vector3 | 使用给定的 x、y、z 分量创建一个新向量。 |
Angle | 计算两个向量之间的角度。 |
ClampMagnitude | 返回向量的副本,其长度被限制为 maxLength。 |
Cross | 两个向量的叉积。 |
Distance | 返回 a 和 b 之间的距离。 |
Dot | 两个向量的点积。 |
Lerp | 在两点之间进行线性插值。 |
LerpUnclamped | 在两个向量之间进行线性插值。 |
Max | 返回一个向量,该向量由两个向量的最大分量组成。 |
Min | 返回一个向量,该向量由两个向量的最小分量组成。 |
MoveTowards | 计算当前和目标指定点之间的一个位置,移动距离不超过 maxDistanceDelta 指定的距离。 |
Normalize | 使此向量的长度为 1。 |
OrthoNormalize | 使向量标准化并相互正交。 |
Project | 将一个向量投影到另一个向量上。 |
ProjectOnPlane | 将一个向量投影到一个平面上。 |
Reflect | 将一个向量反射到由法线定义的平面上。 |
RotateTowards | 将向量 current 旋转到 target。 |
Scale | 按分量将两个向量相乘。 |
SignedAngle | 计算向量 from 和 to 相对于轴的带符号角度。 |
Slerp | 在两个向量之间进行球面插值。 |
SlerpUnclamped | 在两个向量之间进行球面插值。 |
SmoothDamp | 随着时间的推移逐渐将向量更改为所需的目標。 |
operator - | 从一个向量中减去另一个向量。 |
operator != | 如果向量不同,则返回 true。 |
operator * | 将向量乘以一个数字。 |
operator / | 将向量除以一个数字。 |
operator + | 将两个向量相加。 |
operator == | 如果两个向量近似相等,则返回 true。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.