unity中transform组建的功能

核心功能:查找组件,设置位置、角度,父子物体,物体的旋转,移动等

   
if (GUILayout.Button("foreach--transform"))
{
    foreach (Transform child in this.transform)
    {//child为每个子物体的变换组件
        print(child.name);
    }
    this.transform.position物体相对于世界坐标系原点的位置
this.transform.localPosition物体相对于父物体轴心点的位置
rotation同理
 this.transform.localScale;//相对于父物体的缩放比例(1,2,1,高度是父物体的两倍)可读写
    this.transform.lossyScale//理解为物体与模型的缩放比例(自身缩放比例*父物体缩放比例)如:父物体缩放为3,当前物体为2,则lossyscale为6  只读
}
Inspector面板所显示的均为相对于父物体的数值
if (GUILayout.Button("pos/scale"))
{
    this.transform.Translate(0, 0, 1);//向自身坐标轴移动一米
    this.transform.Translate(0, 0, 1, Space.World);//向世界坐标轴移动一米
}
if (GUILayout.Button("translate"))
{
    this.transform.Rotate(0, 0, 10, Space.World);//沿世界坐标轴旋转十度
}
if (GUILayout.RepeatButton("Rotate"))
{
    this.transform.RotateAround(Vector3.zero, Vector3.up, 1);
}
if (GUILayout.Button("foreach--transform"))
{
    Transform rootTF = this.transform.root;//获取根物体变换组件
    Transform ParentTF = this.transform.parent;//获取父物体
    this.transform.SetParent(tf);//不保留当前坐标而保留当前位置
    this.transform.SetParent(tf, false);//保留当前物体相对与世界坐标轴的坐标,即坐标不变但位置变化(坐标原点变化)
}

你可能感兴趣的:(unity基础,c#,c#,unity,unity3d,游戏开发)