坐标系
- 变量
- Right 【X axis】
- Up 【Y axis】
- Forward 【Z axis】
- worldToLocalMatrix
- localToWorldMatrix
- 函数方法
- TransformPoint()【变换位置自身坐标到世界坐标】
- InverseTransformPoint()【变换位置自身坐标到世界坐标】
- TransformDirection()【从自身坐标到世界坐标变换方向】
- InverseTransformDirection()【变换方向从自身坐标到世界坐标】
public GameObject cube
void Awake(){
cube = GameObject.Find ("Cube1")
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.Q)) {
//抓取物体到眼前
cube.transform.position = transform.TransformPoint (0, 0, 2)
//跟随移动
cube.transform.parent = transform
//物体不受其他外力影响
cube.GetComponent<Rigidbody>().isKinematic = true
}
if (Input.GetKey (KeyCode.E)) {
//判断物体是否被抓取
if (cube.transform.parent == this.transform) {
Debug.Log("Local Position" + cube.transform.localPosition.ToString())