Transform保存游戏对象的位置(position),旋转值(rotation),和缩放(scale);
每个gameobject都会有一个Transform组件,不能删除也不能创建一个没有Transform组件的gameobject;
如果gameobject有父节点,则面板上显示的是相对于父节点的值,如果没有父节点,则显示的是相对于世界坐标的值;
属性
1. Transform.position
2. Transform.localPosition { get; set; }
4. Transform.eulerAngles { get; set; }
5. Transform.localEulerAngles { get; set; }
6. Transform.right { get; set;}
7. Transform.up { get; set; }
8. Transform.forward { get; set; }
9. Transform.rotation { get; set; }
10. Transform.position { get; set; }
11. Transform.localRotation { get; set; }
12. Transform.parent { get; set; }
13. Transform.worldToLocalMatrix { get; }
14. Transform.localToWorldMatrix { get; }
15. Transform.root { get; }
16. Transform.childCount { get; }
17. Transform.lossyScale { get; }
18. Transform.hasChanged { get; set; }
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void Update()
{
if (transform.hasChanged)
{
print("The transform has changed!");
transform.hasChanged = false;
}
}
}
19. Transform.localScale { get; set; }
20. Transform.hierarchyCapacity { get; set; }
21. Transform.hierarchyCount { get; }
方法
[FreeFunction("DetachChildren", HasExplicitThis = true)]
1. public void DetachChildren();
2. public Transform Find(string n);
[Obsolete("FindChild has been deprecated. Use Find instead (UnityUpgradable) -> Find([mscorlib] System.String)", false)]
3. public Transform FindChild(string n);
[FreeFunction("GetChild", HasExplicitThis = true)]
[NativeThrows]
4. public Transform GetChild(int index);
[NativeMethod("GetChildrenCount")]
[Obsolete("warning use Transform.childCount instead (UnityUpgradable) -> Transform.childCount", false)]
5. public int GetChildCount();
6. public IEnumerator GetEnumerator();
7. public int GetSiblingIndex();
8. public Vector3 InverseTransformDirection(Vector3 direction);
9. public Vector3 InverseTransformDirection(float x, float y, float z);
10. public Vector3 InverseTransformPoint(float x, float y, float z);
11. public Vector3 InverseTransformPoint(Vector3 position);
12. public Vector3 InverseTransformVector(Vector3 vector);
13. public Vector3 InverseTransformVector(float x, float y, float z);
[FreeFunction("Internal_IsChildOrSameTransform", HasExplicitThis = true)]
14. public bool IsChildOf([NotNull] Transform parent);
15. public void LookAt(Transform target, [DefaultValue("Vector3.up")] Vector3 worldUp);
16. public void LookAt(Vector3 worldPosition, [DefaultValue("Vector3.up")] Vector3 worldUp);
17. public void LookAt(Vector3 worldPosition);
18. public void LookAt(Transform target);
19. public void Rotate(float xAngle, float yAngle, float zAngle);
20. public void Rotate(Vector3 eulers, [DefaultValue("Space.Self")] Space relativeTo);
21. public void Rotate(Vector3 eulers);
22. public void Rotate(float xAngle, float yAngle, float zAngle, [DefaultValue("Space.Self")] Space relativeTo);
23. public void Rotate(Vector3 axis, float angle, [DefaultValue("Space.Self")] Space relativeTo);
24. public void Rotate(Vector3 axis, float angle);
25. public void RotateAround(Vector3 point, Vector3 axis, float angle);
[Obsolete("warning use Transform.Rotate instead.")]
26. public void RotateAround(Vector3 axis, float angle);
[Obsolete("warning use Transform.Rotate instead.")]
27. public void RotateAroundLocal(Vector3 axis, float angle);
28. public void SetAsFirstSibling();
29. public void SetAsLastSibling();
30. public void SetParent(Transform p);
[FreeFunction("SetParent", HasExplicitThis = true)]
31. public void SetParent(Transform parent, bool worldPositionStays);
32. public void SetPositionAndRotation(Vector3 position, Quaternion rotation);
33. public void SetSiblingIndex(int index);
34. public Vector3 TransformDirection(float x, float y, float z);
35. public Vector3 TransformDirection(Vector3 direction);
36. public Vector3 TransformPoint(float x, float y, float z);
37. public Vector3 TransformPoint(Vector3 position);
38. public Vector3 TransformVector(float x, float y, float z);
39. public Vector3 TransformVector(Vector3 vector);
40. public void Translate(float x, float y, float z);
41. public void Translate(float x, float y, float z, [DefaultValue("Space.Self")] Space relativeTo);
42. public void Translate(Vector3 translation);
43. public void Translate(Vector3 translation, [DefaultValue("Space.Self")] Space relativeTo);
44. public void Translate(float x, float y, float z, Transform relativeTo);
45. public void Translate(Vector3 translation, Transform relativeTo);