Create a material that tiles to fit an object?

As far as I can tell a normal material with a texture applied needs to have its tiling property manually changed to fit the size and dimensions of what you are putting it on. Is there a way to have a one-size-fits-all material which will not require manual tuning?

2 Answers

2

This is pretty easy if you can use the world coordinates (or some consistent multiple) as the uv coordinates. This can be done in scripting if you are transforming your objects. Or in a shader.

There is if you write some code to do it, probably based on renderer.bounds. Note that this will require a different material for every differently-sized object; it's not possible for a single material to do that when you're setting the texture scale.

I was afraid it'd have to be a script. Would the script that changed the material change all materials simultaneously, or only that instance of that material on the gameobject the script is attached two?

That's up to you; changing renderer.material automatically creates a new instance, but you can also use sharedMaterial.