- Home /
dynamic UV's on a plane (projecting textures?)
sorry I dont know what the proper term for this is, but basically what Im trying to accomplish is in my game, Im able to stretch and compress a plane. I dont want the texture to stretch or compress with it. I want it to stay exactly the same and just tile as the plane gets bigger.
Can anyone point me to any liturature or documentation on the subject, or at least let me know the proper term for what Im trying to do so I can look it up more easily lol.
Thanks
Answer by Jessy · May 13, 2011 at 02:18 PM
As you scale the verts, you can scale the UVs the same way. However, Unity makes this a bit more accessible, by giving you a shortcut to part of the matrix that can affect the UVs. This way, you leave the UV data of the mesh unaltered:
http://unity3d.com/support/documentation/ScriptReference/Material-mainTextureScale.html
http://unity3d.com/support/documentation/ScriptReference/Material.SetTextureScale.html
renderer.material.mainTextureScale = transform.localScale;
That assumes a plane that is oriented in its own XY plane. If you were to use Unity's plane, which is aligned with the XZ plane, it could be
renderer.material.mainTextureScale = Vector2(transform.localScale.x, transform.localScale.z);