• 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
3
Question by ibyte · Dec 09, 2009 at 06:29 AM · texturematerialuv

Switch between uv and uv2 on one texture

I have a simple model that is made from 1 quad. UV1 is mapped to one area of the texture and UV2 is mapped to a different area on the texture. Unity displays the object using UV1. During game play I would like the object to sometimes use UV2 as the texture mapping for t$$anonymous$$s object. How do I tell unity to temporarily use UV2 instead of UV1?

Comment
Add comment
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

2 Replies

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

Answer by Lance Sun · Dec 09, 2009 at 02:18 PM

MeshFilter meshFilter = go.GetComponent<MeshFilter>();
Mesh mesh = meshFilter.mesh;
Vector2[] temp = mesh.uv;
mesh.uv = mesh.uv2;
mesh.uv2 = temp;

Note that t$$anonymous$$s will cause a copy of the mesh to be created, and the engine will create a new VBO to put the data into.

Comment
Add comment · 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
4

Answer by Jaap Kreijkamp · Dec 09, 2009 at 07:20 AM

Unfortunately t$$anonymous$$s is less trivial than it sounds. It can be done in several ways, for example using a script that sets the mesh.uv to the mesh.uv2 set or using a custom shader that can switch between the meshes. An easier method, assuming you don't have a really weird mapping is instead of using 2 uv sets just use one and use texture positioning to switch to different parts of the texture. To give an example:

using UnityEngine; using System.Collections;

public class UpdateTexture : MonoBehaviour {

 public Material background;

 void SetVerticalOffset(float verticalOffset) {
 Vector2 offset = new Vector2(0f, verticalOffset);
     background.SetTextureOffset("_MainTex", offset);
 }

}

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 ibyte · Dec 09, 2009 at 03:30 PM 0
Share

While I accepted the answer below I think I will end up using your approach. Thanks

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

No one has followed this question yet.

Related Questions

Assigning UV Map to model at runtime 0 Answers

Identical material with different textures 0 Answers

UV tiling to fill face? 1 Answer

can't put texture materials on imported mesh. 1 Answer

Blender UV Material? 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