【原】unity3D小地圖教程


1。從頂視圖上截取一張場景圖,命名為map。
2。找一個圓圈圖標,作為playerTexture.
3.創建panle作為地面。
實際代碼如下:

 public    Texture map  ;
 public Texture playerTexture ;
float cubePosX=0 ;
float cubePosY=0 ;
public  GameObject player  ;
public GameObject plane;
float planeWidth;
void Start()
{
    planeWidth=plane.GetComponent<MeshFilter>().mesh.bounds.size.x*plane.transform.localScale.x;//因為plane是正方形,所以只取了寬
}

void OnGUI ()
{
    GUI.DrawTexture(new Rect(0,0,map.width,map.height),map);
    GUI.DrawTexture(new Rect(cubePosX,cubePosY,25,25),playerTexture);
}

void Update()
{
    cubePosX =map.width*player.transform.position.x/planeWidth+map.width/2;//根據palyer在plane的比例關系,映射到對應地圖位置。
    cubePosY =map.height*player.transform.position.z/planeWidth+map.height/2;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM