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; }