Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by Martin 11 · May 26, 2011 at 08:53 PM · textureuv

How do I map a texture to a primitive instance?

I have 2 primitive cubes, one twice as big as the other and with the same material applied (with defuse shader) - Without duplicating the material, How do I set the UV of the bigger one different to the smaller one?

I assume duplicating the material just to have different Tiling settings is a)possible b)a hit to the engine unnecessarily c)a really clumsy, long-way-round method of achieving goal.

I've taken a look around this and other sites and whilst I seem to be on the cusp of finding the answer, it eludes me! I'm a novice coder, so please be gentle/obvious. THANKS!

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by testure · May 26, 2011 at 09:21 PM

You can do this using the built in material scale vector: renderer.material.mainTextureScale = new Vector2(x,y);

More info: http://unity3d.com/support/documentation/ScriptReference/Material.SetTextureScale.html

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
0

Answer by Eric5h5 · May 26, 2011 at 09:29 PM

You must duplicate the material in order to have different tiling settings. It's impossible for one material to have different settings. The only way to have different UV mapping on different objects while using one material is to change the UVs of the meshes themselves, using the Mesh class.

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 Martin 11 · May 27, 2011 at 05:56 PM 0
Share

do you mean I need to create meshes in an external package?

avatar image Eric5h5 · May 27, 2011 at 06:07 PM 0
Share

No, use the $$anonymous$$esh class as I mentioned. It's easier to use multiple materials though.

avatar image
0

Answer by Martin 11 · May 27, 2011 at 05:35 PM

So testures answer led me to the web page where I took their code example for animated texture, removed the animated bit and created this

 var scaleX : float;
 var scaleY : float;
 
 function Start () {
 
 renderer.material.SetTextureScale ("_MainTex", Vector2(scaleX,scaleY));
 
 }


This allows me to, at run time, have the texture scaled as needed. Of course the downside of this is that in the editor it looks highly stretched. Given this step towards the right answer can anyone suggest how I'd get the editor to look correct? Better still, how to have the script auto-adjust based on the primitive's actual scale?

Comment
Add comment · Show 3 · 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 Eric5h5 · May 27, 2011 at 05:52 PM 0
Share

Using SetTextureScale at runtime just results in Unity creating a duplicate of the material for you. If you look in the editor inspector while running, you can see the material name now has "(Instance)" appended to it, because it's a new copy of the material and not the original. As I said in my answer, it's impossible to do what you want using one material.

avatar image Martin 11 · May 27, 2011 at 05:56 PM 0
Share

well, yes, technically it's 'impossible' (if you say so) - but if I hadn't dug around, I wouldn't have found this auto-fixing solution using a script which does exactly what I need it to, see$$anonymous$$gly.

avatar image Eric5h5 · May 27, 2011 at 06:06 PM 0
Share

Sure, that's fine if you're only concerned with the runtime, and you let Unity generate the necessary material duplicates for you. I'm replying to your question about the editor...you won't be able to have multiple objects using different UV scales look correct using one material in the editor.

avatar image
0

Answer by Martin 11 · May 27, 2011 at 05:46 PM

So, figured this out:

 function Start () {
 
 renderer.material.SetTextureScale ("_MainTex", Vector2((transform.localScale.z/4),(transform.localScale.y/4)));
 
 }

The above code will grab the ZY values and autoscale the texture appropriately. If I want to see the North/South facing quads then it's a XY script I need (am applying this to a cube.

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

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

Get a UV texture of a models surface 2 Answers

Does Unity support multi-tile texture workflows? 0 Answers

Using Rpg maker XP Tiles (2D Tile System) 2 Answers

Automatic mesh combine and texture atlasing 4 Answers


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