zoukankan      html  css  js  c++  java
  • Unity position和localposition

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

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

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

    image

    代码:

    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));
    
    
        }
    
    }
    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    Python之路:堡垒机实例
    Django入门
    阿里云centos安装svn和submin
    发邮件功能
    [Coci2015]Divljak
    [2018多省省队联测]劈配
    [AHOI2009]最小割
    [HAOI2017]新型城市化
    [SDOI2014]LIS
    Loj #2256. 「SNOI2017」英雄联盟
  • 原文地址:https://www.cnblogs.com/plateFace/p/4216407.html
Copyright © 2011-2022 走看看