收集的两种小地图脚本
不知道时效如何,或者是什么版本,暂未测试
unity3d---小地图
终于把小地图做出来了哈哈,记录一下
public var worldRefObj : Transform;//场景侦测参考物体;
public var worldPObj : Transform;//场景侦测物体;
public var mapBg : Texture2D;//地图背景;
public var mapPe : Texture2D;//指针背景;
private var mapPos : Vector2;
private var angle : float;//指针旋转
private var mapPeSize;//指针大小
function Update()
{
var worldPos = Vector2(worldPObj.transform.position.x - worldRefObj.transform.position.x,worldPObj.transform.position.z - worldRefObj.transform.position.z);
var worldRefObjSize = Vector2(worldRefObj.transform.collider.size.x,worldRefObj.transform.collider.size.z);
var mapBgSize = Vector2(mapBg.width,mapBg.height);
mapPeSize = Vector2(mapPe.width,mapPe.height);
angle = worldPObj.rotation.eulerAngles.y;
mapPos = Vector2(worldPos.x * mapBgSize.x/worldRefObjSize.x-mapPeSize.x/2, worldPos.y * mapBgSize.y/worldRefObjSize.y+mapPeSize.x/2);
//Debug.Log(mapPeSize);
}
function OnGUI()
{
GUI.DrawTexture(Rect(0,0,mapBg.width,mapBg.height),mapBg);
GUIUtility.RotateAroundPivot (angle, Vector2(mapPos.x+mapPeSize.x*0.5,-mapPos.y+mapPeSize.y*0.5));
Debug.Log(mapPeSize);
GUI.DrawTexture(Rect(mapPos.x,-mapPos.y,mapPe.width,mapPe.height),mapPe);
}
009-04-01 11:27:56| 分类: 虚拟现实(vr) |字号 订阅
代码:
@script ExecuteInEditMode()
public var blip : Texture; //定一指文件代表角色
public var radarBG : Texture; //地背景片,我直接用景里我建的render texture
public var centerObject : Transform; //角色的物的位置信息
public var mapScale = 0.3; //地放
public var mapCenter = Vector2(50,50); //地中心
function OnGUI () {
bX=centerObject.transform.position.x * mapScale;
bY=centerObject.transform.position.z * mapScale;
bX=centerObject.transform.position.x * mapScale;
bY=centerObject.transform.position.z * mapScale;
GUI.DrawTexture(Rect(mapCenter.x-32,mapCenter.y-32,64,64),radarBG);
// 上面的mapCenter.x-32是地的x位置,mapCenter.y-32是y位置,64,64是地的大小
DrawBlipsForEnemies();
}
function DrawBlipsForCows(){
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Cow");
var distance = Mathf.Infinity;
var position = transform.position;
for (var go : GameObject in gos) {
drawBlip(go,blip);
}
}
function drawBlip(go,aTexture){
centerPos=centerObject.position;
extPos=go.transform.position;
dist=Vector3.Distance(centerPos,extPos);
dx=centerPos.x-extPos.x;
dz=centerPos.z-extPos.z;
deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
bX=bX*mapScale;
bY=bY*mapScale;
if(dist<=200){
GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,2,2),aTexture);
}
}
function DrawBlipsForEnemies(){
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Enemy");
var distance = Mathf.Infinity;
var position = transform.position;
for (var go : GameObject in gos) {
drawBlip(go,blip);
}
}
後半部份自己慢慢理解下,存js文件即可使用
出处web3d虚拟神话论坛 http://bbs.vrsh.cn