Tansfrom 类又是Unity中非常重要的类,也是一个特别的类.我们都知道Unity是基于组件开发的引擎.在每个GameObject的Inspector界面有很多组件,我们可以为它添加新的组件或者移除;在里面第一个组件就是Transform,他与其他组件的不同是所有GameObject都必须拥有它,删不掉.它记录了这个游戏对象的位置(Position),旋转角度(Rotation),缩放比例Scale),在此position 涉及向量,旋转角度涉及四元数(Quaternion),这些知识我们以后会逐一仔细研究.
还有一个需要知道,Transform组件里还有一个父子级属性,可以得到当前transform的父级transform和当前的所有子transform及它们的属性.
下面是Transform类里的成员变量和方法
Variables变量
-
The position of the transform in world space.
在世界空间坐标 transform的位置。 -
Position of the transform relative to the parent transform.
相对于父级的变换的位置。 -
The rotation as Euler angles in degrees.
旋转作为欧拉角度。 -
The rotation as Euler angles in degrees relative to the parent transform's rotation.
旋转作为欧拉角度,相对于父级的变换旋转角度。 -
The red axis of the transform in world space.
在世界空间坐标变换的红色轴。也就是x轴。 -
The green axis of the transform in world space.
在世界空间坐标变换的绿色轴。也就是y轴。 -
The blue axis of the transform in world space.
在世界空间坐标变换的蓝色轴。也就是z轴。 -
The rotation of the transform in world space stored as a Quaternion.
在世界空间坐标物体变换的旋转角度作为 Quaternion储存。 -
The rotation of the transform relative to the parent transform's rotation.
物体变换的旋转角度相对于父级的物体变换的旋转角度。 -
The scale of the transform relative to the parent.
相对于父级物体变换的缩放。 -
The parent of the transform.
物体变换的父级。 -
Matrix that transforms a point from world space into local space (Read Only).
矩阵变换的点从世界坐标转为自身坐标(只读)。 -
Matrix that transforms a point from local space into world space (Read Only).
矩阵变换的点从自身坐标转为世界坐标(只读)。 -
Returns the topmost transform in the hierarchy.
返回层次最高的变换。 -
The number of children the Transform has.
变换的子物体数量。 -
The global scale of the object (Read Only).
物体的全局缩放(只读)。
Functions函数
-
Moves the transform in the direction and distance of translation.
移动 transform在translation的方向和距离。 -
Applies a rotation of eulerAngles.z degrees around the z axis, eulerAngles.x degrees around the x axis, and eulerAngles.y degrees around the y axis (in that order).
应用一个欧拉角的旋转角度,eulerAngles.z度围绕z轴,eulerAngles.x度围绕x轴,eulerAngles.y度围绕y轴(这样的顺序)。 -
Rotates the transform about axis passing through point in world coordinates by angle degrees.
按照angle度通过在世界坐标的point轴旋转物体。 -
Rotates the transform so the forward vector points at /target/'s current position.
旋转物体,这样向前向量指向 target的当前位置。 -
Transforms direction from local space to world space.
从自身坐标到世界坐标变换方向。 -
Transforms a direction from world space to local space. The opposite of Transform. TransformDirection.
变换方向从世界坐标到自身坐标。和 Transform.TransformDirection相反。 -
Transforms position from local space to world space.
变换位置从自身坐标到世界坐标。 -
Transforms position from world space to local space. The opposite of Transform. TransformPoint.
变换位置从世界坐标到自身坐标。和 Transform.TransformPoint相反。 -
Unparents all children.
所有子物体解除父子关系。 -
Finds a child by name and returns it.
通过名字查找子物体并返回它。 -
Is this transform a child of parent?
这个变换是父级的子物体?
Inherited members继承成员
Inherited Variables继承变量
-
The Transform attached to this GameObject (null if there is none attached).
Transform附加到 GameObject(游戏物体)(如无附加则为空)。 -
The Rigidbody attached to this GameObject (null if there is none attached).
Rigidbody 附加到 GameObject(游戏物体)(如无附加则为空)。 -
The Camera attached to this GameObject (null if there is none attached).
Camera 附加到 GameObject(游戏物体)(如无附加则为空)。 -
The Light attached to this GameObject (null if there is none attached).
Light 附加到 GameObject(游戏物体)(如无附加则为空)。 -
The Animation attached to this GameObject (null if there is none attached).
Animation 附加到 GameObject(游戏物体)(如无附加则为空)。 -
The ConstantForce attached to this GameObject(null if there is none attached).
ConstantForce 附加到 GameObject(游戏物体)(如无附加则为空)。 -
The Renderer attached to this GameObject (null if there is none attached).
Renderer 附加到 GameObject(游戏物体)(如无附加则为空)。 -
The AudioSource attached to this GameObject(null if there is none attached).
AudioSource 附加到 GameObject(游戏物体)(如无附加则为空)。 -
The GUIText attached to this GameObject (null if there is none attached).
GUIText 附加到 GameObject(游戏物体)(如无附加则为空)。 -
The NetworkView attached to this GameObject(Read Only). (null if there is none attached)
NetworkView 附加到 GameObject(游戏物体)(只读)(如无附加则为空)。 -
The GUITexture attached to this GameObject(Read Only). (null if there is none attached)
GUITexture附加到 GameObject(游戏物体)(只读)(如无附加则为空)。 -
The Collider attached to this GameObject (null if there is none attached).
Collider附加到 GameObject(游戏物体)(如无附加则为空)。 -
The HingeJoint attached to this GameObject (null if there is none attached).
HingeJoint附加到 GameObject(游戏物体)(如无附加则为空)。 -
The ParticleEmitter attached to this GameObject(null if there is none attached).
ParticleEmitter附加到 GameObject(游戏物体)(如无附加则为空)。 -
The game object this component is attached to. A component is always attached to a game object.
组件附加的游戏物体。一个组件总是被附加到一个游戏物体。 -
The tag of this game object.
游戏物体的标签。
-
The name of the object. //物体的名字
-
Should the object be hidden, saved with the scene or modifiable by the user?
物体是否被隐藏、保存在场景中或被用户修改?
Inherited Functions继承函数
-
Returns the component of Type type if the game object has one attached, null if it doesn't.
如果游戏物体有一个附加,则返回Type类型的组件,如果没有则为null。 -
-
Returns the component with name type if the game object has one attached, null if it doesn't.
如果游戏物体有一个附加,则返回名字类型组件,如果没有则为null。 -
Returns the component of Type type in the GameObject or any of its children using depth first search.
返回Type类型组件,在 GameObject或它的任何子物体使用深度优先搜索,仅返回激活的组件。 -
-
Returns all components of Type type in the GameObject or any of its children.
在 GameObject或任何它的子物体,返回全部Type类型组件 -
-
Returns all components of Type type in the GameObject.
在游戏物体返回全部Type类型组件。 -
-
Is this game object tagged tag?
游戏物体有被标记标签么? -
Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour
在游戏物体每一个 MonoBehaviour和每一个behaviour的祖先上调用名为methodName的方法。 -
Calls the method named methodName on every MonoBehaviour in this game object.
在游戏物体每一个 MonoBehaviour上调用名为methodName的方法。 -
Calls the method named methodName on every MonoBehaviour in this game object or any of its children.
在游戏物体每一个 MonoBehaviour和它的全部子物体上调用名为methodName的方法。
-
Returns the instance id of the object.
返回物体的实例ID -
Returns the name of the game object.
返回游戏物体的名称。
Inherited Class Functions继承类函数
-
Does the object exist?
物体是否存在? -
Clones the object original and returns the clone.
克隆原始物体,并返回克隆的物体 -
-
Removes a gameobject, component or asset.
删除一个游戏物体、组件或资源 -
Destroys the object obj immediately. It is strongly recommended to use Destroy instead.
立即销毁物体obj,强烈建议使用Destroy代替。 -
Returns a list of all active loaded objects of Type type.
返回Type类型的所有激活的加载的物体列表 -
Returns the first active loaded object of Type type.
返回Type类型第一个激活的加载的物体。 -
Compares if two objects refer to the same
比较如果两个物体相同 -
Compares if two objects refer to a different object
比较如果两个物体不同 -
Makes the object target not be destroyed automatically when loading a new scene.
加载新场景的时候使目标物体不被自动销毁。