Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Stephanides · Dec 29, 2014 at 01:44 PM · texturecubetiling

Auto tiling texture

Hello, i have a little problem. I adding texture after spawn cube for example but this cube spawn in not the same localScale.z . I need to have tiling of texture the same on all objects, how can i do this ? Here is picture how i have it. But i want the same texture on both of them . Thank you a lot. alt text

tiling.png (253.0 kB)
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
1
Best Answer

Answer by taxvi · Dec 29, 2014 at 01:54 PM

 transform.renderer.material.SetTextureScale("_MainTex", new Vector3(1f / transform.scale.z, 1));
 

also try multiplying the z value with some coefficients if this does not work.

EDIT: fixed the code line

Comment
Add comment · Show 9 · 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 Stephanides · Dec 29, 2014 at 02:24 PM 1
Share

transform.renderer.material.SetTextureScale("_$$anonymous$$ainTex", new Vector2(rozdiel / 1000f, 0.01f)); //this working for me , thank you very much

avatar image chris3331 · Oct 06, 2015 at 03:14 PM 0
Share

Hey, what if I got the same problem but need to fix it in a EditorWindow-Script? I can´t use "transform" here!

avatar image taxvi chris3331 · Oct 06, 2015 at 03:19 PM 0
Share
         foreach (Object o in Selection.objects) {
             GameObject go = (GameObject)o;
 
             //for each selected object do:
             //do whatever
         }

avatar image chris3331 · Oct 06, 2015 at 03:48 PM 0
Share

I'm sorry to bother you taxvi, but I don't know how to use your hint. I would like to fix the size of the texture independent to the size of the object.

$$anonymous$$y c# Code:

 public class Editor_Change$$anonymous$$aterial_08_Link: EditorWindow 
 {    
     [$$anonymous$$enuItem("Add-on/Change material)")] 
     
     public static void Change()
     {
         GameObject SelectedObject = Selection.activeGameObject;    
         $$anonymous$$aterial[] materials = SelectedObject.GetComponent<Renderer> ().shared$$anonymous$$aterials;
         .
         .
         .
 
         Texture2D New$$anonymous$$apTex = Resources.Load ("Texture/" +common[c]+"_TextureLink") as Texture2D;  
         SelectedObject.GetComponent<Renderer> ().shared$$anonymous$$aterials[1].SetTexture("_$$anonymous$$ainTex", New$$anonymous$$apTex);
         
         
         // * Here I would like to fix the size of the texture
 
         //m.mainTextureScale = new Vector2(1f, 1f);            
         //m.mainTextureOffset = new Vector2(0.0f, 0.0f);            
     }
 }                    

i just can't figure it out :( thanks in advance!!

avatar image taxvi chris3331 · Oct 06, 2015 at 04:04 PM 0
Share

oh, then after the line

 SelectedObject.GetComponent<Renderer> ().shared$$anonymous$$aterials[1].SetTexture("_$$anonymous$$ainTex", New$$anonymous$$apTex);

add

 SelectedObject.GetComponent<Renderer> ().shared$$anonymous$$aterials[1].SetTextureScale("_$$anonymous$$ainTex", /* whatever the scale */);
avatar image chris3331 taxvi · Oct 06, 2015 at 05:00 PM 0
Share

I did this! -->

 SelectedObject.GetComponent<Renderer> ().shared$$anonymous$$aterials[1].SetTextureScale("_$$anonymous$$ainTex",  new Vector2(3f, 3f));

... and it is still just tiling dependent to the size of the surface! I want my script to put the texture of bricks on surfaces with different sizes without changing the size of the bricks!

But still thanks a lot for your effort!! :)

Show more comments
avatar image taxvi chris3331 · Oct 06, 2015 at 04:31 PM 0
Share

cast the SelectedObject to a GameObject and then use gameObject.transform. should do it :/ but maybe I still don't understand what you need

avatar image chris3331 taxvi · Oct 06, 2015 at 07:37 PM 0
Share

Unfortunately it didn't work neither! I'm now trying something according to this: http://answers.unity3d.com/questions/756419/how-to-make-a-texture-fit-on-all-objects.html

 var factor = 1; 
 $$anonymous$$esh mf = SelectedObject.GetComponent<$$anonymous$$eshFilter>().shared$$anonymous$$esh;
 if (mf != null)
 {
     Bounds bounds = mf.bounds;
 
     Vector3 size = Vector3.Scale(bounds.size, SelectedObject.transform.localScale) * factor;
     if (size.y < .001)
     {
         size.y = size.z;
     }
                                 
     m.mainTextureScale = size;
 }

I still don´t have full controll of the size of the texture but I´m getting closer :)

avatar image
0

Answer by Stephanides · Dec 29, 2014 at 01:56 PM

Whats mean MainTex?

Comment
Add comment · Show 4 · 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 taxvi · Dec 29, 2014 at 02:01 PM 0
Share

use "add new comment" under the answers for questions like this, and "_$$anonymous$$ainTex" is the shader's property name for its texture

avatar image Stephanides · Dec 29, 2014 at 02:08 PM 0
Share

Okay, but infortunatly this not working

avatar image taxvi · Dec 29, 2014 at 02:19 PM 0
Share

well you can debug what's wrong there or look for something else :/

avatar image Stephanides · Dec 29, 2014 at 02:27 PM 0
Share

Its good now , thank you

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

29 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 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 avatar image avatar image avatar image

Related Questions

Dynamically tiling texture on a cube of changing scale. 1 Answer

Texture is Tied to Two Cubes 1 Answer

Real Sized Texture Tiling 2 Answers

Assigning UV Map to model at runtime 0 Answers

How to make a texture tile and not stretch 5 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