8
\$\begingroup\$

I have read the whole unity manual and watched the videos on sprites but I have a question. Is there any way of creating primitive 2D shapes in unity? (I will be assigning trigger colliders to these as well). Or does one need to have a 3rd-party program even for basic primitive 2D shapes? My game really is very minimalist.

I did think about using particle system in a clever way but that won't have triggers and may not be as memory efficient for the several basic shapes that I am after.

\$\endgroup\$
5
\$\begingroup\$

Yes, the Mesh object used for the MeshFilter and MeshRenderer can be modified to create any kind of 2D shape you like.

You'd do this by generating a 2D mesh of triangles to represent the shape you want. The bonus to using a Mesh object is that you can automatically use that as a collider too. This means that your shapes have easy interaction with operations like click detection and ray casting.

The Unity Manual partially covers how to generate these. I made a video tutorial about it (sorry it's paid). There's also a number of YouTube tutorials of varying quality.

Further, it's completely possible to create a 3D model (that's 2D) in a 3D modeling application and import it into Unity. Again, this will use the Mesh object and you can use the generated mesh as a collision mesh too.

\$\endgroup\$
5
  • \$\begingroup\$ Thank you for your kind reply. And what will the performance be like if I have many of these Mesh objects in the scene instead of the same number of sprites? \$\endgroup\$
    – Tomatoes
    Feb 11 '15 at 21:19
  • \$\begingroup\$ BTW that course is on my MUST-BUY radar. It's an amazing course from what I can tell from the few preview vids. Keep up the good work, sir! \$\endgroup\$
    – Tomatoes
    Feb 11 '15 at 21:21
  • \$\begingroup\$ Mesh objects are very common in Unity, they're used for most objects displayed in the game. I think your performance will be just fine. My course does cover object pools in the Optimization chapter, which may be useful if you have a number of these objects being loaded and unloaded. You can do a 10-day free trial of Lynda.com, my course included. Make sure you have some spare time to get the most of your 10 days :) \$\endgroup\$
    – House
    Feb 11 '15 at 21:35
  • \$\begingroup\$ I can't thank you enough! Hopefully, my mobile game won't get bogged down by them BUT I will make sure I check out your course and optimization chapter just to be on the safe side. Amazing stuff \$\endgroup\$
    – Tomatoes
    Feb 11 '15 at 21:39
  • 2
    \$\begingroup\$ Just as a side note: Mesh colliders are more expensive than cube or sphere colliders, as they must be recomputed every time the mesh is moved, rotated, or scaled. \$\endgroup\$ Jan 13 '16 at 16:56

You must log in to answer this question.

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