Transform类学习
Transform 变换,是场景中最常打交道的类,用于控制物体的位移,旋转,缩放等功能。
Transform
Class, inherits from Component, IEnumerable
Position, rotation and scale of an object.
控制物体的位置,旋转和缩放。
Every object in a scene has a Transform. It’s used to store and manipulate the position, rotation and scale of the object. Every Transform can have a parent, which allows you to apply position, rotation and scale hierachically. This is the hierarchy seen in the Hierarchy pane. They also support enumerators so you can loop through children using:
每一个场景中的物体都有Transform这个类,他是用来储存和处理物体的位移,旋转和缩放的。每一个Transform都可以有一个父物体,这可以让你得到下游节点的位移旋转和缩放。这个层次结构关系可以从Hierarchy面板中看到。他还支持enumerators,以使用循环来遍寻所有的子节点。
all transform children 10 units upwards!
for (var child : Transform in transform) {
child.position += Vector3.up * 10.0;
}
Variables 属性
position: Vector3 绝对位置,相对于世界坐标物体的位置。
localPosition: Vector3 相对位置,或自身位置,物体相对于父物体的位置。
eulerAngles: Vector3 轴向旋转角度,相对于世界坐标轴。单位为度,而非弧度。运行时的数值在(0,360)。
localEulerAngles: Vector3 相对轴向旋转角度,或自身的旋转角度,物体相对于父物体