Transform.TransformPoint 变换位置
function TransformPoint (position : Vector3) : Vector3
Description描述
Transforms position from local space to world space.
变换位置从自身坐标到世界坐标。
Note that the returned position is affected by scale. Use Transform.TransformDirection if you are dealing with directions.
注意,返回位置受缩放影响。如果你是处理方向使用Transform.TransformDirection。
C#
JavaScript
using UnityEngine;using System.Collections;public class example : MonoBehaviour {public GameObject someObject;public Vector3 thePosition = transform.TransformPoint(Vector3.right * 2);public void Awake() {Instantiate(someObject, thePosition, someObject.transform.rotation);}}
// You need to assign an object to this variable in the inspector//在检视面板你必须指定一个物体到这个变量var someObject : GameObject;// Instantiate an object to the right of the current object//在当前物体的右边,实例化物体var thePosition = transform.TransformPoint(Vector3.right * 2);Instantiate(someObject, thePosition, someObject.transform.rotation);
• function TransformPoint (x : float, y : float, z : float) : Vector3
Description描述
Transforms the position x, y, z from local space to world space.
变换位置 x, y, z从自身坐标到世界坐标。
Note that the returned position is affected by scale. Use Transform.TransformDirection if you are dealing with directions.
注意,返回位置受缩放影响。如果你是处理方向使用Transform.TransformDirection。
C#
JavaScript
using UnityEngine;using System.Collections;public class example : MonoBehaviour {public GameObject someObject;public void Awake() {thePosition = transform.TransformPoint(2, 0, 0);Instantiate(someObject, thePosition, someObject.transform.rotation);}}
// You need to assign an object to this variable in the inspector//你必须在检视面板指定一个物体到这个变量var someObject : GameObject;// Instantiate an object to the right of the current object//在当前物体的右边实例化一个物体thePosition = transform.TransformPoint(2, 0, 0);Instantiate(someObject, thePosition, someObject.transform.rotation);