找回密码
 立即注册
楼主: monery8

[GUI] Unity3D小地图代码

  [复制链接]
发表于 2012-12-16 15:46 | 显示全部楼层 |阅读模式
[code=csharp]
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);
}
}[/code]
发表于 2013-5-15 17:42 | 显示全部楼层

感谢楼主的无私分享!{:soso__11402694654016840197_7:}
发表于 2013-7-27 14:53 | 显示全部楼层
{:5_397:}{:5_412:}{:5_412:}{:5_412:}{:5_387:}
发表于 2013-7-31 15:38 | 显示全部楼层
不错啊,谢谢

点评

不错不错,简单明了!  详情 回复 发表于 2013-8-1 09:57
发表于 2013-8-1 09:57 | 显示全部楼层
零零七 发表于 2013-7-31 15:38
不错啊,谢谢

不错不错,简单明了!
发表于 2015-6-11 15:48 | 显示全部楼层
非常棒!回去试试!
发表于 2017-6-8 22:10 | 显示全部楼层
好帖就是要顶
发表于 2017-6-8 22:22 | 显示全部楼层
真心顶
发表于 2017-6-8 21:46 | 显示全部楼层
说的非常好
发表于 2017-6-8 21:40 | 显示全部楼层
不错不错
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-2 08:44 , Processed in 0.070125 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表