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 Eowyn27 · Dec 16, 2013 at 06:43 PM · textureobjectmaterialsselection

I want to add stripes at varying lengths on my object. How do I do that?

So let's say I have an object and I want to add stripes at varying lengths on my object. How can I do that?

I assume it has something to do with adding an extra layer of material or texture. How do I add another material/texture at a certain length on my object?

See picture below for what I'm trying to achieve.

alt text

Also I want to make the stripes I added selectable.

texture sample.png (18.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
2
Best Answer

Answer by Owen-Reynolds · Dec 16, 2013 at 06:54 PM

A "95%" method might be to add colored cylinders (with capsule colliders?) sticking out just a little. (The idea being, 95% of what you thought you wanted is often good enough, and the last 5% will be a huge pain.)

Otherwise, remodel it with submeshes where the stripes should be. Each will give a material slot in Unity (once you have it, can easily test by hand-coloring in the Inspector.) For selection, I'd still go with an invisible sphere/capsule collider. Give it a tiny script with just int stripeNum;.

Comment
Add comment · Show 6 · 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 OP_toss · Dec 16, 2013 at 07:09 PM 0
Share

Agreed, I gave the 5% answer below. Bit more work, but will avoid many $$anonymous$$or issues. Specifically, no misaligned cylinders intercolliding with mesh, no zfighting if the cylinders are too close to the mesh, and no baking the number and position of the cylinders into the mesh.

But whatever suits your needs most.

avatar image Eowyn27 · Dec 17, 2013 at 08:14 PM 0
Share

I have tried Owen Reynolds solution. However, when I want to select the tree and not the stripes, it becomes hard to do because sometimes unity won't let me select anything or it will select the stripes and not the tree. I can only select the tree on the ends of the objects and not behind strips.

avatar image Owen-Reynolds · Dec 18, 2013 at 12:53 AM 0
Share

How large are the colliders? And, if the stripes are children of the big tree, or vice-versa, ray cast needs to use, ummm, collision.collider ins$$anonymous$$d of collision.transform.

avatar image Eowyn27 · Dec 23, 2013 at 06:02 PM 0
Share

I have one more question, how do instantiate the cylinders? Let's say I just have the tree. Then when the user clicks on the tree, the tree is replaced with the tree with the cylinders ins$$anonymous$$d of a plain tree?

avatar image Owen-Reynolds · Dec 23, 2013 at 06:26 PM 0
Share

I was thinking hand-place the cylinders, and have them always be "on." The cylinders are the stripes.

If the number and position of stripes changes as the game plays, ouch. Could mark out a bezier curve using empties, for position/width. But the hard method with hand-made UVs and 1 material/stripe starts to look better.

Show more comments
avatar image
1

Answer by OP_toss · Dec 16, 2013 at 07:06 PM

Yeah you've got the right idea.

Easiest solution would be to use multiple materials, then get the uv coord from the raycasthit, and thus which line was selected.

Now in more detail:

So to add a single stripe, make a texture with one horizontal line in it. Set the repeat to Clamp, and make sure the top and bottom edges are transparent.

To add a line to the mesh:

  1. Find the Mesh Renderer and set the Materials size to 2.

  2. Make a new transparent material and set the texture to your line. Add it below the default material. It should make a line over your mesh.

  3. Adjust the Tiling to get the line how you like.

  4. Repeat per line you need added.

Note: This requires proper UVs that are aligned along the lines you want. This also assumes you will need to add and remove lines often, and you want to determine exactly WHICH line was selected. If this is wrong reply and I'll adjust the answer.

In order to make them selectable:

  1. On Mouse Down, perform a Collider.Raycast/Physics.Raycast from the mouse position along it's direction. If you hit the collider, continue.

  2. Get the texcoord from the RaycastHit object. With a little math you should be able to get the pixel value from the uv coordinate. Remember the uv may be in relation to the first material, so it may be a bit off.

  3. Check if the alpha of the pixel is above a certain threshold in order to determine if it is indeed a stripe. You'll know which line by which material uv offsets you're using.

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 Eowyn27 · Dec 17, 2013 at 08:39 PM 0
Share

I will try your method sometime this week and see if I run into any trouble. Seems interesting. 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.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Changing scrolling textures on a plane using transparency 1 Answer

A node in a childnode? 1 Answer

Textures are not tiling properly on my wall model! 3 Answers

Transparent Texture2D 2 Answers

Objects on minimap replaced with icon? 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