首页 > 代码库 > Unity position和localposition
Unity position和localposition
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)); }}
Unity position和localposition
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。