- Home /
Ring with changeable diameters
I have a problem and don't have idea how to solve it. It's propably something easy, but I can't figure it out, so I would appreciate some help.
I want to "draw" a ring which dimensions (inner diameter - d1 and outer diameter - d2) I would be able to control independently, i.e. changing one diameter won't affect second one. I also want to be able to change any of the diameter during normal execution (for example - the ring will pulsate). The ring have some color/texture but it's center is completly transparent. Here's schematic to what I want to achieve:
I've tried doing it as circle sprite and make inner hole with SetPixel(s) function, but it's too expensive operation. Also I've tried using UI mask with hole in it (the rectangular mask is used to show the problem better). The problem I've got is:
If I want to have smaller hole I shrink the mask. In this case the mask cuts too much and I don't have proper object anymore.
If I want to have bigger hole I make mask bigger. In some point my mask will go beyond image and user will see it.
So my problem is - how to make such ring with changeable diameters? Or is there any way to mask objects "in reverse"? Thanks in advance for any help. :)
Answer by komodor · May 08, 2015 at 02:04 PM
option 1: create mesh where you can control radiuses (http://docs.unity3d.com/es/current/ScriptReference/Mesh-vertices.html)
option 2: create shader with the both radius properties and color property and do it whole by shader (the code won't be too different from your setpixel code) (http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html)
Your answer
Follow this Question
Related Questions
UI Masking (Type visiblity of the content outside and inside of mask ) 0 Answers
UI mask with a 3D object 1 Answer
Can I combine 2 or more UI masks? 0 Answers
TextMeshPro InputField masking not working 0 Answers
Mask 3D objects inside UI ScrollRect 4 Answers