- Home /
Shifting the UV's of a plane
Hello, all! My GUI will be primarily composed of GUITextures and textured planes. I have rendered out a sprite sheet for the different images a plane would display and then mapped it to one of these images. I would like to know if I could, via scripting, change the UV coordinates of each vertex of the plane to map it to my desired image on the sprite sheet. This will save space and time. Thanks! - YA
Oh dear. Yeah that's looking like a negative. Shoestring budget over here. Although it looks quite impressive. I guess I'll just have to painstakingly render out each individual sprite -_-
You want to shift the UVs for textures on GUITextures, not regular meshes, right?
I meant meshes. I didn't know there was a way to UV map a GUITexture.
I don't think you all quite understand what I want here... I have a sprite sheet of 9 symbols, all similarly sized. There are 18 sprites in a grid formation in all (One for the symbol when the mouse is not over it and one for when the mouse IS over it). I would like to make a plane and assign it that material. Then, based on what ID it has in the code (what symbol it is assigned), it will change it's coordinates for both the active and inactive images accordingly. Any way that I can simply DEFINE, not animate, the UV coordinates in a static fashion? Thanks- YA
Answer by ThePunisher · Oct 08, 2012 at 11:23 PM
You might want to look into the following methods:
renderer.material.SetTextureScale("_MainTex", new Vector2(scale.x, scale.y));
renderer.material.SetTextureOffset("_MainTex", new Vector2(pos.x, pos.y));
This will allow you to control what part of the texture is displayed on your mesh.
Thank you so much this is what I needed. I can't believe I didn't just think of shifting the main texture. That's why I made all elements on the sheet similarly sized. This is actually all I would need to totally alter UV coordinates for a plane (besides rotation) Thanks so much! - YA
Answer by Michael Covert · Oct 08, 2012 at 11:22 PM
You can change the mesh uvs associated with the plane, sure. The unity documentation for Mesh.uv has a pretty good example actually:
http://docs.unity3d.com/Documentation/ScriptReference/Mesh-uv.html
Does that not meet your needs? If not, what is it that you're missing?
Holy cow that is complicated.. Just open your mesh in blender and open the UV tab. From there you can properly position your UV texture maps without using coded coordinates.
Your answer
Follow this Question
Related Questions
How I can stretch texture with GUI.DrawTextureWithTexCoords ? 1 Answer
Player Fast Travels 1 Answer
Accessing 4.6 GUI build-in sprites in C# 0 Answers
Cube Counter 1 Answer
Get Mouse Position GUI 3 Answers