# How to use uv mapping in Unity 2017

I want to create a game with a Minecraft style world. Now I need uv mapping for some cubes in my game. But I could not find any good tutorial in the internet. I want to use the following texture with an uv map:

Each side of the cube has a texture with 64x64 pixels. The dirt texture on the right side has to be the top of the cube. Can anyone tell me how to use uv mapping in my case?

• You need a program called blender for uv mapping, not unity
– user100681
Mar 9, 2018 at 15:52
• I already tried blender for it. But then I have cubes which scales are different from the cubes in Unity. Mar 9, 2018 at 15:57
• that is not the problem. You cannot (directly) specify Uv coordinates using Unity; That's why 3D modeling programs are being used. All you need to do is create the model in blender, unwrap it to the wanted texture, import it into unity and set the "scale factor" option to a reasonable number(from the import settings window). If you don't want to do that, you can just scale the cube in blender
– user100681
Mar 9, 2018 at 16:42
• I'm confused. You already showed in a previous question that you have a script that will construct a cube mesh with your desired UV mapping. What more do you hope to learn from this question that isn't covered by your existing solution? I'll also second Philipp's caution: you will not be able to draw a large Minecraft world by spawning individual cubes. You'll need to construct a skin mesh of just the visible surfaces. Mar 9, 2018 at 17:20
• Then ask about your actual problem: "using this script [include code], I see artifacts on my cube. How can I correct these artifacts?" Mar 9, 2018 at 17:29

You can specify UV coordinates in Unity: https://docs.unity3d.com/ScriptReference/Mesh-uv.html

The UV coordinates go from 0 to 1, and the index in the uv array corresponds the the vertex with the matching index in the vertices array. This Unity Answers post may prove useful. It lists the vertices in Unity's cube primitive. The top face is first in the vertices, so you would map the uvs of the top face in the first four indices of the uv array like this:

uv[0] = (1, .333)
uv[1] = (.75, .333)
uv[2] = (1, .667)
uv[3] = (.75, .667)


I'll leave it to you to figure out the rest of the faces. Of course, assigning the uvs in a script would be more ideal only if you are generating content at runtime, so making your own mesh in a program like blender would be more ideal ... or you could make a script that runs in the Editor to create a new mesh for you based on the cube primitive. You can do this using the AssetDatabase interface.

• Can you add a full script I can use? Mar 9, 2018 at 17:17
• I'll add part of a script from a similar project soon. But I would recommend following the links I posted. That first one has some example code for assigning uvs. Mar 9, 2018 at 17:27
• You can specify UV coordinates, yes, but that's not the ideal solution sometimes. In this case, you might wanna do it this way, calculating the texture coordinates in relation to a spritesheet (since it's minecraft), but most of the times it's much better to uv unwrap your 3D models into a 3D modeling program like blender or maya
– user100681
Mar 9, 2018 at 17:42