码迷,mamicode.com
首页 > 其他好文 > 详细

transform.position和transform.localPosition区别

时间:2016-08-01 20:57:25      阅读:668      评论:0      收藏:0      [点我收藏+]

标签:

1. position是根据世界原点为中心


2. localPosition是根据父节点为中心,如果没有父节点,localpositon和position是没有区别的


3.选中一个物体左上角Global和Local切换看物体世界坐标轴和本地坐标轴

技术分享

 

using UnityEngine;
using System.Collections;


public class TestPostiton : MonoBehaviour {
void OnGUI() 
{
if (GUI.Button(new Rect(0, 0, 200, 50), "世界坐标移动"))
{
this.gameObject.transform.position = new Vector3(gameObject.transform.position.x+1
,gameObject.transform.position.y
, gameObject.transform.position.z);
}


if (GUI.Button(new Rect(0, 50, 200, 50), "本地坐标移动"))
{
this.gameObject.transform.localPosition = new Vector3(gameObject.transform.localPosition.x+1
, gameObject.transform.localPosition.y 
, gameObject.transform.localPosition.z);
}


GUI.Label(new Rect(210, 0, 300, 50), "世界坐标:" + string.Format("({0},{1},{2})", gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z));
GUI.Label(new Rect(210, 50, 300, 50), "本地坐标:" + string.Format("({0},{1},{2})", gameObject.transform.localPosition.x, gameObject.transform.localPosition.y, gameObject.transform.localPosition.z));




}


}

 

transform.position和transform.localPosition区别

标签:

原文地址:http://www.cnblogs.com/unity3ds/p/5727066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!