UnityTransform常识(转)
Variables
position: Vector3  物体在世界坐标中的位置。 transform.position=Vector3(10,10,10)//把物体放到(x=10,y=10,z=10)的位置
localPosition: Vector3  相对位置,或⾃⾝位置,物体相对于⽗物体的位置。
eulerAngles: Vector3  轴向旋转⾓度,相对于世界坐标。单位为度(°)
localPosition: Vector3 相对轴向旋转⾓度,或⾃⾝的旋转⾓度,物体相对于⽗物体的旋转。⼀般使⽤和处理物体的旋转⾓度时都会使⽤到这个数值。
right: Vector3  物体⾃⾝的红⾊轴向(X轴)在世界坐标中所指向的位置。注意在maya中x轴指向物体的左边,⽽unity中的x轴则指向物体的右边。
rigidbody.velotity=transform.right*moveSpeed;//向物体的右侧以moveSpeed的速度移动
up: Vector3  物体⾃⾝的绿⾊轴向(Y轴)在世界坐标中所指向的位置。
forward: Vector3  物体⾃⾝的蓝⾊轴向(Z轴)在世界坐标中所指向的位置。
rotation: Quaternion  以四元数来表达的物体⾃⾝的旋转。四元数可以快速的处理物体的旋转⽅向的计算,搭配Quaternion可以⽤来计算各种需要的旋转⽅案。具体应⽤⽅法参见Quaternion篇
localRotation: Quaternion 相对于⽗物体的⽤四元数来表达的旋转。
localScale: Vector3 物体相对于⽗物体的缩放
parent: Transform 物体的⽗物体。如果没有则返回null。如果改变⽗物体的位置,旋转和缩放,会同时影响并改变⼦物体的位置,旋转和缩放,但是保持相对位置,相对旋转和相对缩放。
worldToLocalMatrix: Matrix4x4 ⼀个表达从世界坐标到相对坐标位置的四维矩阵,Read Only。如果你对矩阵不是很了解,请使⽤Transform.InverseTransformPoint。LocalToWorldMatrix: Matrix4x4 ⼀个表达从相对坐标到世界坐标位置的四维矩阵,Read Only。如果你对矩阵不是很了解,请使⽤Transform.TransformPoint。
root: Transform  返回物体的最⾼层的⽗物体。如果物体本⾝就是最⾼层,则返回物体本⾝。
childCount: Int  返回物体的⼦物体数量。float up
lossyScale:Vector3 返回物体相对于世界坐标的缩放值。 Read Only。没什么⽤的⼀个属性,当⼦物体被旋转后也不是特别精确,也不推荐⼤家⽤。如果想要计算物体的世界坐标缩放,最好⾃⼰写计算公式。
Functions
1)Translate,⽤来移动物体的函数,⾮常常⽤的⼀个函数。
function Translate (translation : , relativeTo :  = ) : void
把物体向translation⽅向移动,距离为translation.magnitude。 relativeTo表⽰这个移动的参考坐标系。
function Translate (x : float, y : float, z : float, relativeTo :  = ) : void
同上
function Translate (translation : , relativeTo : Transform) : void
如果relativeTo 不是null,则以⽬标物体relativeTo的⾃⾝轴向作为参考坐标系。
function Translate (x : float, y : float, z : float, relativeTo : Transform) : void
同上
脚本:
var speed=30;
//将物体以30⽶每秒的速度向前移动。
trasform.Translate(Vector3.forward*speed*Time.deltaTime);
2)Rotate,⽤来旋转物体的函数,⾮常常⽤,在知道需要旋转的⾓度的情况下。如果要让物体旋转到指定位置,需要搭配Quaternion来使⽤。
function Rotate (eulerAngles : , relativeTo :  = ) : void
旋转eulerAngles度(3个轴向分别旋转),以relativeTo为参考坐标系
function Rotate (xAngle : float, yAngle : float, zAngle : float, relativeTo :  = ) : void
同上
function Rotate (axis : , angle : float, relativeTo :  = ) : void
以axis为轴旋转angle度,以relativeTo为参考坐标系
3)RotateAround 让物体以某⼀点为轴⼼成圆周运动。
function RotateAround (point : , axis : , angle : float) : void
让物体以point为中⼼,绕axis为轴向旋转angle度。保持原来与point的距离。
4)LookAt 让物体的z轴看向⽬标物体
function LookAt (target : Transform, worldUp :  = ) : void
让物体的z轴看向target的位置,并以worldUp为y轴指向⽅向。
function LookAt (worldPosition : , worldUp :  = ) : void
让物体看向worldPosition
5)TransformDirection
function TransformDirection (direction : ) :
返回以物体⾃⾝为坐标轴的向量direction在世界坐标中的朝向向量。
function TransformDirection (x : float, y : float, z : float) :
同上
6)InverseTransformDirection
function InverseTransformDirection (direction : ) :
function InverseTransformDirection (x : float, y : float, z : float) :
与TransformDirection相反,从世界坐标转换到⾃⾝相对坐标。
7)TransformPoint
function TransformPoint (position : ) :
function TransformPoint (x : float, y : float, z : float) :
把⼀个点从⾃⾝相对坐标转换到世界坐标
8)InverseTransformPoint
function InverseTransformPoint (position : ) :
function InverseTransformPoint (x : float, y : float, z : float) :
把⼀个点从时间坐标转换到⾃⾝坐标的位置。
9)DetachChildren
function DetachChildren () : void
把⾃⾝所有的⼦物体的⽗物体都设成世界,也就是跟⾃⼰的所有⼦物体接触⽗⼦关系。
10)Find
function Find (name : string) : Transform
到⼀个名字是name的物体并返回
如果没有到则返回null。如果字符串被/隔离,函数则会像⽂件路径⼀样逐级下查。
/
/ The magical rotating fingerfunction Update() {aFinger = transform.Find("LeftShoulder/Arm/Hand/Finger");aFinger.Rotate(*20, 0, 0);} 11)IsChildOf
function IsChildOf (parent : Transform) : bool
如果物体是parent的⽗⼦层级关系下的⼀员,返回true;