Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

C# Uv mapping problem

$
0
0
Ok so I have been learning to uv map proocedural meshes in unity. The problem I am having is I dont understand how to wrap the whole thing, I understand how to uv a plane but a 3d cube, please help! Code: `using UnityEngine; using System.Collections; public class BlockDirt : MonoBehaviour{ Block block; public void Start(){ block = new Block(); block.setBlockName("test"); blockCreate(this.transform.position); Vector3 prevPos = this.transform.position; this.gameObject.AddComponent().mesh=blockCreate(this.transform.position); this.gameObject.AddComponent(); //this.gameObject.GetComponent().materials[0] = (Material)Resources.Load("Textures/Blocks/BlockMat"); this.transform.position=prevPos; Debug.Log("test"); } public Mesh blockCreate(Vector3 pos){ Mesh mesh = new Mesh(); int scale = 2; Vector3[] verts = new Vector3[8]; Vector2[] uvs = new Vector2[12]; int[] tris; verts[0]=pos+new Vector3(0,0,0); verts[1]=pos+new Vector3(scale,0,0); verts[2]=pos+new Vector3(scale,0,scale); verts[3]=pos+new Vector3(0,0,scale); verts[4]=pos+new Vector3(0,scale,0); verts[5]=pos+new Vector3(scale,scale,0); verts[6]=pos+new Vector3(scale,scale,scale); verts[7]=pos+new Vector3(0,scale,scale); tris=new int[]{0,1,2, 0,2,3, 0,5,1, 0,4,5, 4,6,5, 4,7,6, 3,6,7, 3,2,6, 0,7,4, 0,3,7, 1,5,6, 1,6,2 }; uvs[0]=new Vector2(0,0); uvs[1]=new Vector2(0,0.125f); uvs[2]=new Vector2(0.125f,0.125f); uvs[3]=new Vector3(0.125f,0); uvs[4]=new Vector2(0,0); uvs[5]=new Vector2(0,0.125f); uvs[6]=new Vector2(0.125f,0.125f); uvs[7]=new Vector3(0.125f,0); mesh.vertices = verts; mesh.triangles = tris; mesh.RecalculateNormals(); mesh.uv = uvs; //mesh.RecalculateBounds(); return mesh; } }`

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>