绘制小地图
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1新建一个renderTexture命名为minmapTexture新建一个fps角色
2、新建一个cmeraFollow脚本并付给摄像机。
using UnityEngine;
using System.Collections;
public class cameraFollow : MonoBehaviour {
public Transform target;
void LateUpdate () {
transform .position =new Vector3 (target .position.x,transform .position .y,target.position .z);
}
}
3target为fps,并将摄像机的dipth改为1
4、给地形一个标签命名为ninmap
5、将所有的culling target 改为minmap
将main camera 的target texture 改为minimap。
6、新建一个plane 将minmaTexture托给他会制动生成一个minmapTexure 材质
7新建一个shader 命名为maskShade
8 把里面的脚本删除了然后再粘贴如下脚本。
Shader "Custom/Mask"
{
Properties
{
_MainTex ("Main Texture", 2D) = "white" {}
_Mask("Mask Texture", 2D) = "white" {}
}
SubShader
{
Tags { "Queue"="Transparent" }
Lighting On
Zwrite off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
SetTexture[_Mask]{combine texture}
SetTexture[_MainTex]{combine texture ,previous}
}
}
}
9、在photoshop中绘制你要的地图形状并保存alpha通道保存为tag格式。
并且注意要修改它的textureType为advant 并且把aphaformgrayScale勾选。
】
10、选中生成的材质shader菜单下的mask 把从ps中绘制的地图现状拖过去即生成了小地图。
11、如果看不到小地图就调节总摄像机下的normalized View port Rect改为x:0 y:0,w:1, H:1
12下面在游戏中生成小地图。
13新建一个c#脚本
输入如下代码using UnityEngine;
using System.Collections;
public class guiTexure : MonoBehaviour {
public RenderTexture minmapTexture;
public Material minmapMaterial;
//
void OnGUI () {
if( Event.current.type==EventType.Repaint )
Graphics .DrawTexture (new Rect(0,0,256,256),minmapTexture, minmapMaterial);
}
}
13将他拖到任何一个物体上using UnityEngine;
minmapTexture;为minmapTexture
minmapMaterial为生成的minmapTexture材质
运行一下小地图出来了哈哈~很好玩赶快试一下吧
方法2:
@script ExecuteInEditMode()
public var Enemy_ : Texture; //define enemy texture
public var Box_:Texture;//define the box texture
public var Player_:Texture;//define player texture
public var radarBG : Texture; //small map texture
public var centerObject : Transform; //chracter position
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-55,mapCenter.y-50,128,128),radarBG);
// 上面的mapCenter.x-32是地圖的x位置,mapCenter.y-32是y位置,64,64是地圖的大小
DrawBlipsForEnemies();
DrawBlipsForPlayer();
DrawBlipsForBox();
}
function DrawBlipsForBox(){ //draw box texture in small map
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Box");
var distance = Mathf.Infinity;
var position = transform.position;
for (var go : GameObject in gos) {
drawBlip(go,Box_);
}
}
function DrawBlipsForPlayer(){ //draw player texture in small map
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Player");
var distance = Mathf.Infinity;
var position = transform.position;
for (var go : GameObject in gos) {
drawBlip(go,Player_);
}
}
function DrawBlipsForEnemies(){ //draw enemy texture in small map
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Enemy");
var distance = Mathf.Infinity;
var position = transform.position;
for (var go : GameObject in gos) {
drawBlip(go,Enemy_);
}
}
function drawBlip(go,aTexture){ //draw position in small map
centerPos=centerObject.position;
extPos=go.transform.position;
dist=Vector3.Distance(centerPos,extPos);