• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by youngapprentice · Oct 05, 2012 at 09:22 PM · guispriteuv

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

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaveA · Oct 05, 2012 at 10:51 PM 0
Share

You might want to grab NGUI, will save you time.

avatar image youngapprentice · Oct 05, 2012 at 10:55 PM 0
Share

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 -_-

avatar image DaveA · Oct 05, 2012 at 11:09 PM 0
Share

You want to shift the UVs for textures on GUITextures, not regular meshes, right?

avatar image youngapprentice · Oct 06, 2012 at 12:53 AM 0
Share

I meant meshes. I didn't know there was a way to UV map a GUITexture.

avatar image youngapprentice · Oct 06, 2012 at 10:59 PM 0
Share

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

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image youngapprentice · Oct 12, 2012 at 11:36 PM 0
Share

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

avatar image ThePunisher · Oct 15, 2012 at 04:49 PM 0
Share

You are welcome, thanks for tagging the answer.

avatar image
2

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?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DJAspire · Sep 27, 2018 at 05:40 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to add sprites to a canvas via scripting 1 Answer

Sprites and minmizing memory usage 1 Answer

What to use for dynamic loading of assets instead of Resources.Load()? 1 Answer

Efficient way to keep a fixed rotation for sprite? 0 Answers

Why is texture blurred in one GuiStyle and not in another? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges