Quantcast
Channel: Questions in topic: "shade"
Viewing all articles
Browse latest Browse all 14

Shader wants texture coordinates, but the mesh doesn't have them H

$
0
0
I try to make a copy of Minecraft in Unity.I wroted a chunk script,but I have this error: Shader wants texture coordinates, but the mesh doesn't have them Can everyone help me?? Here's a chunk script: using UnityEngine; using System.Collections; using System.Collections.Generic; [RequireComponent (typeof(MeshFilter))] [RequireComponent (typeof(MeshCollider))] public class Chunk : MonoBehaviour { public int width = 16; public byte[,,] map; protected Mesh mesh; protected MeshCollider meshCollider; protected List verts = new List(); protected List tris = new List(); public List uv = new List(); // Use this for initialization void Start () { meshCollider = GetComponent(); map = new byte[width, width, width]; for (int x = 0; x ().mesh = mesh; Regenerate(); } // Update is called once per frame void Update () { } public void DrawBrick(int x, int y, int z, byte block){ Vector3 start = new Vector3(x,y,z); Vector3 offset1, offset2; if (IsTransparent(x, y - 1, z)){ offset1 = Vector3.left; offset2 = Vector3.back; DrawFace(start + Vector3.right, offset1, offset2, block); } if (IsTransparent(x, y + 1, z)){ offset1 = Vector3.right; offset2 = Vector3.back; DrawFace(start + Vector3.up, offset1, offset2, block); } if (IsTransparent(x - 1, y, z)){ offset1 = Vector3.up; offset2 = Vector3.back; DrawFace(start, offset1, offset2, block); } if (IsTransparent(x + 1, y, z)){ offset1 = Vector3.down; offset2 = Vector3.back; DrawFace(start + Vector3.right + Vector3.up, offset1, offset2, block); } if (IsTransparent(x, y, z - 1)){ offset1 = Vector3.left; offset2 = Vector3.up; DrawFace(start + Vector3.right + Vector3.back, offset1, offset2, block); } if (IsTransparent(x, y, z + 1)){ offset1 = Vector3.right; offset2 = Vector3.up; DrawFace(start, offset1, offset2, block); } } public void DrawFace(Vector3 start, Vector3 offset1, Vector3 offset2, byte block) { int index = verts.Count; verts.Add(start); verts.Add(start + offset1); verts.Add(start + offset2); verts.Add(start + offset1 + offset2); Vector2 uvBase; switch (block) { default: uvBase = new Vector2(0.25f,0.25f); break; case 2 : uvBase = new Vector2(0.75f,75f); break; case 3 : uvBase = new Vector2(0.25f,0.75f); break; } if((offset1 == Vector3.right) && (offset2 == Vector3.back)) { uv.Add(uvBase); uv.Add(uvBase + new Vector2(0.125f,0)); uv.Add(uvBase + new Vector2(0,0.125f)); uv.Add(uvBase + new Vector2(0.125f,0.125f)); }else{ uv.Add(uvBase); uv.Add(uvBase + new Vector2(-0.125f,0)); uv.Add(uvBase + new Vector2(0,0.125f)); uv.Add(uvBase + new Vector2(-0.125f,0.125f)); } tris.Add(index + 0); tris.Add(index + 1); tris.Add(index + 2); tris.Add(index + 3); tris.Add(index + 2); tris.Add(index + 1); } public bool IsTransparent(int x,int y,int z){ if ((x = width) || (y >= width) || (z >= width)) return true; return map[x,y,z] == 0; } public void Regenerate() { verts.Clear(); tris.Clear(); uv.Clear(); mesh.triangles = tris.ToArray(); for (int x = 0; x = width) || (y >= width) || (z >= width)) return; if (map[x,y,z] != block){ map[x,y,z] = block; Regenerate(); } } } ` Screenshots: ![alt text][1] ![alt text][2] [1]: /storage/temp/20646-asd.png [2]: /storage/temp/20647-asd.png P.s. Sorry for my english

Viewing all articles
Browse latest Browse all 14

Latest Images

Trending Articles



Latest Images