- Home /
Apply texture to a bar (cube)
Hi,
I'm feeling so stupid to ask this question but I didn't find any help.
I try to apply a texture to this bar. But it's impossible to tile this texture a way that it looks nice on every face of the cube. Is there a way to texture the cube's faces individually?
What do I have to do so it looks like this (right side):
http://www.youtube.com/watch?v=e3v3PMenNwY
Sorry for my bad english.
Crosspost: http://forum.unity3d.com/threads/179821-Apply-texture-to-a-bar-(cube)
Answer by AlucardJay · Apr 25, 2013 at 07:42 PM
Are you using a texture? You can use :
http://docs.unity3d.com/Documentation/ScriptReference/Material-mainTextureScale.html
http://docs.unity3d.com/Documentation/ScriptReference/Material.SetTextureScale.html
Set the tiling based on the scale of the object :
function Update ()
{
var scaleX : float = transform.localScale.x;
var scaleY : float = transform.localScale.y;
renderer.material.mainTextureScale = Vector2( scaleX, scaleY );
}
Yes but I can set this in the inspector, too. And there seems to be no combination of scaleX and scaleY so the cube looks nice on every side :(
If you are using native objects and material, then unfortunately this is the problem you will have. To get the effect in the video, you need to UV map each face.
Check my answer here on UV mapping the Unity native cube : http://answers.unity3d.com/questions/306959/uv-mapping.html
Answer by DaveA · Apr 25, 2013 at 08:13 PM
You should either:
a) make the cube from 6 separate planes, texture each with a different material, all using the same texture, but tile as needed, group under an empty game object
b) use a modeler like Blender or Maya or Max and create a UV map for the single mesh cube you're using. Adjust the UV map as needed, then you can use one material.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101010im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Unity3D - Ammo Texture repeat 2 Answers
Texturing/Coloring wherever you go 1 Answer
Unity3d - Minecraft 3 Answers