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

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

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);
最后修改:2010年12月19日 Sunday 16:21

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。