unity 获取和设置gameObject的坐标


// 获取Player变量指定的对象的三围坐标

Vector3 player_postion = Player.transform.position;

 

// 获取X,Y,Z值

 float x = player_postion.x;

 float y = player_postion.y;

 float z = player_postion.z;

 

// 设置应用了当前函数的GameObject的坐标

// 1.直接赋值

this.GetComponent<Transform>().position = player_postion;

// 2.在某GameObject的基础上加

this.GetComponent<Transform>().position = new Vector3(player_postion.x, player_postion.y + 7.79F, player_postion.z - 15);

//或者是

this.GetComponent<Transform>().position = player_postion + new Vector3(0, 7.79F, -15);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM