纳金网

标题: 【转】小地图代码的实现 [打印本页]

作者: 晃晃    时间: 2011-7-26 07:54
标题: 【转】小地图代码的实现

    public var blip : Texture; //代表角色
    public var blip_other : Texture;//敌人
    public var radarBG : Texture; //地图背景图片
    public var centerObject : Transform; //角色位置
    public var mapScale = 0.6; //地图缩放
    public var mapCenter = Vector2(50,50); //地图中心
    function OnGUI () {
        bX=centerObject.position.x * mapScale;
        bY=centerObject.position.z * mapScale;
        
        //bX=centerObject.transform.position.x * mapScale;
        //bY=centerObject.transform.position.z * mapScale;
        
        GUI.DrawTexture(Rect(mapCenter.x -50,mapCenter.y - 50,100,100),radarBG);
        GUI.DrawTexture(Rect(mapCenter.x,mapCenter.y,4,4),blip);
       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 + 90 - centerObject.eulerAngles.y;
      
        bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
        bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
      
        bX=bX*mapScale*7;
        bY=bY*mapScale*7;
      
        if(dist<=20){  //20以内的敌人显示
           GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,4,4),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_other);
        }
    }

作者: 彬彬    时间: 2011-8-2 21:26

作者: 菜刀吻电线    时间: 2011-8-20 11:12
好啊!!
作者: tc    时间: 2012-2-21 23:22
长了不少见识

作者: C.R.CAN    时间: 2012-4-18 23:19
很经典,很实用,学习了!

作者: 菜刀吻电线    时间: 2012-4-27 23:19
我也来支持下

作者: 奇    时间: 2012-5-23 23:19
呵呵,真得不错哦!!

作者: 晃晃    时间: 2012-7-3 23:19
先垫一块,再说鸟

作者: 晃晃    时间: 2012-7-28 23:24
不错不错,收藏了

作者: 她。    时间: 2012-8-3 18:02
我爱纳金网~www.narkii.com
作者: tc    时间: 2012-9-23 23:21
先垫一块,再说鸟

作者: 菜刀吻电线    时间: 2012-12-13 22:49
再看一看,再顶楼主

作者: 菜刀吻电线    时间: 2013-2-10 23:28
发了那么多,我都不知道该用哪个给你回帖了,呵呵





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5