I have 2 primitive cubes, one twice as big as the other and with the same material applied (with defuse shader) - Without duplicating the material, How do I set the UV of the bigger one different to the smaller one?
I assume duplicating the material just to have different Tiling settings is a)possible b)a hit to the engine unnecessarily c)a really clumsy, long-way-round method of achieving goal.
I’ve taken a look around this and other sites and whilst I seem to be on the cusp of finding the answer, it eludes me! I’m a novice coder, so please be gentle/obvious. THANKS!
You can do this using the built in material scale vector:
renderer.material.mainTextureScale = new Vector2(x,y);
More info:
http://unity3d.com/support/documentation/ScriptReference/Material.SetTextureScale.html
You must duplicate the material in order to have different tiling settings. It’s impossible for one material to have different settings. The only way to have different UV mapping on different objects while using one material is to change the UVs of the meshes themselves, using the Mesh class.
So testures answer led me to the web page where I took their code example for animated texture, removed the animated bit and created this
var scaleX : float;
var scaleY : float;
function Start () {
renderer.material.SetTextureScale ("_MainTex", Vector2(scaleX,scaleY));
}
This allows me to, at run time, have the texture scaled as needed. Of course the downside of this is that in the editor it looks highly stretched. Given this step towards the right answer can anyone suggest how I’d get the editor to look correct? Better still, how to have the script auto-adjust based on the primitive’s actual scale?
So, figured this out:
function Start () {
renderer.material.SetTextureScale ("_MainTex", Vector2((transform.localScale.z/4),(transform.localScale.y/4)));
}
The above code will grab the ZY values and autoscale the texture appropriately. If I want to see the North/South facing quads then it’s a XY script I need (am applying this to a cube.