Unity 画小地图的方法重写版

Hi,推荐文件给你 "小地图相关素材.zip" http://vdisk.weibo.com/s/LdtOl


本文代码例子          http://vdisk.weibo.com/s/BDn59yfnC5Xt3

using UnityEngine;
using System.Collections;

public class Scene : MonoBehaviour 
{
	GameObject plane;
	GameObject cube;
	
	float mapWidth;
	float mapHeight;
	
	float widthCheck;
	float heightCheck;
	
	float mapcube_x = 0;
	float mapcube_y = 0;
	
	public Texture map;
	public Texture map_cube;
	
	void Start()
	{
		plane = GameObject.Find("Plane");
		cube = GameObject.Find("Cube");
		float size_x =  plane.GetComponent<MeshFilter>().mesh.bounds.size.x;
		float scal_x = plane.transform.localScale.x;
		
		float size_z = plane.GetComponent<MeshFilter>().mesh.bounds.size.z;
		float scal_z = plane.transform.localScale.y;
		
		mapWidth = size_x * scal_x;
		mapHeight = size_z * scal_z;
		Check();

	}
	
	void OnGUI()
	{
		if(GUILayout.RepeatButton("left",GUILayout.Height(50)))
		{
			cube.transform.Translate(Vector3.left * Time.deltaTime * 5);
			Check();
		}
		if(GUILayout.RepeatButton("right",GUILayout.Height(50)))
		{
			cube.transform.Translate(Vector3.right * Time.deltaTime * 5);
			Check();
		}
		
		if(GUILayout.RepeatButton("forward",GUILayout.Height(50)))
		{
			cube.transform.Translate(Vector3.forward * Time.deltaTime * 5);
			Check();
		}
		
		if(GUILayout.RepeatButton("back",GUILayout.Height(50)))
		{
			cube.transform.Translate(Vector3.back * Time.deltaTime * 5);
			Check();
		}
		
		GUI.DrawTexture(new Rect(Screen.width - map.width,0,map.width,map.height),map);
		GUI.DrawTexture(new Rect(mapcube_x,mapcube_y,map_cube.width,map_cube.height),map_cube);
		
	}
	
	
	void Check()
	{
		float x = cube.transform.position.x;
		float z = cube.transform.position.z;
		
		
		mapcube_x = (map.width / mapWidth * x) + ((map.width / 2) - (map_cube.width / 2)) + (Screen.width - map.width) ;
		mapcube_y = map.height/ 2 -  (map.height / mapHeight * z) ;
	}
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杜甲同学

感谢打赏,我会继续努力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值