Unity1小地图的制作
using UnityEngine;
using System.Collections;
public class TestMap : MonoBehaviour {
GameObject cube = null;
GameObject plane = null;
public Texture2D map;
public Texture2D point;
private float Width = 0.0f;
private float Height = 0.0f;
private float mapwidth = 0.0f;
private float mapheight = 0.0f;
void Start () {
cube = GameObject.Find ("Cube");
plane = GameObject.Find ("Plane");
float x = plane.GetComponent<MeshFilter> ().mesh.bounds.size.x;
float z = plane.GetComponent<MeshFilter> ().mesh.bounds.size.z;
float sx = plane.transform.localScale.x;
float sz = plane.transform.localScale.z;
Width = x * sz;
Height = z * sz;
}
void Update () {
float xl = cube.transform.position.x - plane.transform.position.x;
float yl = plane.transform.position.y- cube.transform.position.y;
mapwidth = (xl + Width / 2) / Width;
mapheight = (yl + Height / 2) / Height;
}
void OnGUI(){
GUI.DrawTexture (new Rect(450,10,100,75),map);
GUI.DrawTexture (new Rect(450 + 100 * mapwidth,10 + 75 * mapheight,point.width,point.height),point);
}
}
![](https://img-my.csdn.net/uploads/201411/18/1416320541_5539.jpg)