- Home /
The question is answered, right answer was accepted
Scaling/Offsetting a texture based on object size to match up with other objects
I have a 3d block. I can change the blocks scale in all 3 dimensions during runtime. Currently, the block has a material with a texture applied to it. Naturally, when I scale the block, the texture stretches with it.
I would like for the texture to be uniform, regardless of the block size. So if I place two blocks of different size next to each other, I'd like the textures to match up.
Normally, I'd work out something like this by myself, just playing around with different values, however, I haven't really messed around with textures, at all, so I find them a bit confusing. For instance, I realize a texture is an image with 2 dimensions, but my objects scale in 3 dimensions, and I can't wrap my head around how to scale the texture properly in this circumstance.
Any help on this would be appreciated.
Answer by Em3rgency · Jul 03, 2013 at 08:11 PM
Solved the whole problem with this: http://www.blog.radiator.debacle.us/2012/01/joys-of-using-world-space-procedural.html
This is what I wanted all along.
Answer by Quillicit · Jul 03, 2013 at 06:02 AM
For a block, something along these lines should work:
using UnityEngine;
using System.Collections;
public class ScaleTexture : MonoBehaviour {
void Update() {
float scaleX = transform.localScale.x;
float scaleY = transform.localScale.y;
renderer.material.mainTextureScale = new Vector2(scaleX, scaleY);
}
}
No. Please actually read my question before posting an answer. All the blocks are irregularly shaped, NOT CUBES. And they scale in all 3 dimensions, not just x and y.