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