- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
- 纳金币
- -1
- 精华
- 11
|
using UnityEngine;
using System.Collections;
public class Pic : MonoBehaviour {
//假定我们的小地图为128*128pixels
public Texture2D smallMap = new Texture2D(128, 128);
public Texture2D backTexture;//这个是小地图的大的背景图。
public Camera aa;//这里依照摄像机的位置来判断,如果是rpg等有角色的游戏则该成gameobject即可
public float worldwidth = 1000;//世界的宽度和长度,就是游戏场景的大小。我这里假定1000大家可以按照自己游戏的实际大小来写
public float wordheight= 1000;
public float Ratex,Ratey;
private int possmallMapx,possmallMapy;
private int x1,y1;
private Color mapColor;
void Update () {
if (backTexture){
Ratex = (aa.transform.position.x)/worldwidth;
Ratey = (aa.transform.position.z)/wordheight;
possmallMapx = (int)(bigMap.width*Ratex);
possmallMapy = (int)(bigMap.height*Ratey)
x1 = possmallMapx-smallmapbig/2;
y1 = possmallMapy-smallmapbig/2;
for( int y=0; y < 128; ++y) {
for (int x=0; x < 128; ++x) {
mapColor= bigMap.GetPixel(x1+x,y1+y);
smallMap.SetPixel(x,y,mapColor) ;
}
}
smallMap.Apply();
}
}
void OnGUI () {
// 地图绘制在右上角,按照自己习惯,rect 随便修改即可
GUI.DrawTexture(new Rect(Screen.width-128,0,128,128),smallMap);
}
}
|
|