Auto tile texture

I’m making a 2.5D platformer. Things are going well, except the ground texturing. I want to be able to make a cube and scale it however I want with the texture auto-tiling to keep in from stretching. In other words, I want to tile, not stretch, and don’t want to set the tiling manually, because I have many objects with the same texture and don’t want to make a ton of material files with different tiling settings. I was thinking a script may be able to do this… Thanks.

var ScaleToTiles : float = 0.667;

function Start () {
	renderer.material.mainTextureScale.x = transform.lossyScale.x*ScaleToTiles;
	renderer.material.mainTextureScale.y = transform.lossyScale.y*ScaleToTiles;
}

Here is the script that I ended up using. It works great for me. I never change the z scale of my object, but you should be able to modify this script as necessary.