public RectTransform redimg;//小地图中的人物红点 public Transform player;//人物 public Image map;//小地图(父级要有个Mash组件) public Texture2D texture; public int w=50; public int h=50; public Color gaocolor = Color.black; public Color dicolor = Color.white; public float max = 10; // Start is called before the first frame update void Start() { texture = new Texture2D(w,h); VertexHelper vh = new VertexHelper(); for (int x = 0; x < w; x++) { for (int z = 0; z < h; z++) { float noise = Mathf.PerlinNoise(x*0.1f, z*0.1f); float y = noise * max; float uvx = (float)x / (float)(w - 1); float uvy = (float)z / (float)(h - 1); Color color = Color.Lerp(dicolor,gaocolor, noise); texture.SetPixel(x, z, color); vh.AddVert(new Vector3(x, y, z), Color.white, new Vector2(uvx, uvy)); if (x != w - 1 && z != h - 1) { vh.AddTriangle(x * h + z, x * h + z + 1, (x + 1) * h + z + 1); vh.AddTriangle(x * h + z, (x + 1) * h + z + 1, (x + 1) * h + z); } } } texture.Apply(); Mesh mesh = new Mesh(); vh.FillMesh(mesh); GetComponent<MeshFilter>().mesh = mesh; GetComponent<MeshCollider>().sharedMesh = mesh; Material material = new Material(Shader.Find("UI/Default")); material.mainTexture = texture; map.material = material; GetComponent<MeshRenderer>().material = material; } // Update is called once per frame void Update() { float pivotX = (player.transform.position.x ) / (float)w; float pivotY = (player.transform.position.z ) / (float)h; map.rectTransform.pivot = new Vector2(pivotX, pivotY); redimg.transform.eulerAngles = Vector3.back * player.transform.eulerAngles.y; }
标签:material,地形图,Color,float,噪声,texture,柏林,new,public From: https://www.cnblogs.com/z816/p/17217356.html