3
\$\begingroup\$

I want to procedurally create a polygonal shape filled with texture in unity 2d (no 3d meshes). Something that looks like this: https://www.conceptdraw.com/How-To-Guide/picture/landscape-plan/Building-Plans-Landscape-Garden-Design-Elements-Roofs.png

As you can see roofs can be rectangles, but also any polygonal shapes.

Can it be done in vanilla unity 2d? Or should I rely on 3rd party libraries and if so which one would fit best?

p.s. I will most likely overlay that object with PolygonCollider2d for physics

\$\endgroup\$
4
  • \$\begingroup\$ We have a question about dynamically creating textured polygons here. The answer shows shaping the polygon in the editor, but you could use the same script (or similar method) and pass it a list of vertices you've chosen procedurally just as well. \$\endgroup\$
    – DMGregory
    Commented Feb 23, 2019 at 5:33
  • \$\begingroup\$ @DMGregory that one is 3d mesh, my question is for 2d only \$\endgroup\$
    – Zepplock
    Commented Feb 23, 2019 at 21:16
  • \$\begingroup\$ Hint: 2D sprites are actually drawn as 3D meshes anyway. ;) \$\endgroup\$
    – DMGregory
    Commented Feb 23, 2019 at 21:40
  • \$\begingroup\$ Im aware of that ;) My question was more around unity engine best practices. I ended up doing mesh for now. I might change it to something else once I need to texture it better. \$\endgroup\$
    – Zepplock
    Commented Feb 26, 2019 at 16:47

1 Answer 1

2
\$\begingroup\$

Sprite shapes

They allow you to create adbitary polygons filled in with sprites. You can also make the edges different based on the angle.

They've been built into Unity for a a year or so.

\$\endgroup\$
4
  • \$\begingroup\$ This is all done in Unity via UI and not procedurally. Is there an example of creating sprites procedurally? \$\endgroup\$
    – Zepplock
    Commented Feb 23, 2019 at 1:26
  • \$\begingroup\$ @Zepplock You can change the shapes procedurally forum.unity.com/threads/spriteshape-preview-package.522575/… \$\endgroup\$
    – Bálint
    Commented Feb 23, 2019 at 1:33
  • \$\begingroup\$ sprite shapes is a dead link. And SpriteShapeController "could not be found" even after importing UnityEngine.U2D \$\endgroup\$
    – pete
    Commented Jun 24 at 3:52
  • \$\begingroup\$ Edit: Fixed by going to package manager and going to Unity and installing 2D Spriteshape \$\endgroup\$
    – pete
    Commented Jun 24 at 3:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .