您的位置:首页 > 移动开发 > Unity3D

Unity3D_(插件)使用Camera渲染制作Minimap小地图

2018-11-08 22:56 2101 查看

 

 

  制作小地图:使用Camera渲染出来Render Texture

 

  游戏项目已托管到Github上  传送门

 

小地图效果:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyMove : MonoBehaviour {

public float speed =4;

private float timer = 0;
private float dirx = 0;
private float dirz = 0;
// Update is called once per frame
void Update () {
timer += Time.deltaTime;
if (timer > 4)
{
dirx = Random.Range(-1f, 1f);
dirz = Random.Range(-1f, 1f);
timer = 0;
}
transform.Translate(new Vector3(dirx, 0, dirz) * speed * Time.deltaTime);
}
}
EnemyMove.cs  

 

实现过程

 

  给Player添加Quad,作为小地图的mapicon,放到Player正上方并将其x轴旋转90°

  给mapicon添加一个图标,材质设为Diffuse(透明)

  给mapicon一个Minimap标签

 

  给每个敌人AI一个红色的icon

 

  添加一个Camera放到Player中,Position设置为(0,9,0),X轴旋转90°,命名为minimap-camera

  设置minimap-camera的Projection为Orthographic

  minimap-camera小地图大小由Size控制

  为了将在小地图上看不见敌人,将Culling Mask取消Human的渲染

 

  将小地图渲染的视觉渲染到Render Texture图片上

  创建一个新的Render Texture,命名为minimap-texture,将minimap-texture绑定到minimap-camera上的Target Texture

 

 

使用NGUI添加小地图进场景中

 

  添加NUI编辑包

  如果遇到提示RuntimePlatform.WindowsWebPlayerNGUI过时,将WindowsWebPlayerNGUI修改为WindowsPlayerNGUI

  添加NGUI中第一个背景UI Root

 

  UI Root添加一个Simple Texture

  将Texture放到UI Root右上角并将minimap-texture指定到UITexture上的Texture中

  将Texture下的Anchors设置为Unified,放置到UI Root右上方

 

 

  将正方形地图制作成圆形地图

  制作一个自定义材质Mask,取名minimap-mat

  

  将minimap-mat放置到Texture下的Material中,可通过改变Size来改变小地图的大小

 

  切换3D视角,地图camera渲染地面

  Main Camera和minimap-camera下的Culling Mask设置渲染Ground标签(地面)

  

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: