- Home /
Coloring a EdgeCollider2D GameObject
I am trying to draw screen boundaries for my first game in unity. I have managed to generate random EdgeCollider2D points which plots the boundary. Below image shows what I've done so far,
I am now trying to color the region between the camera end and the edge collider. Rough idea of what I am trying to implement,
I am not able to figure out a way to get this done. Am I missing anything so simple or is my approach for creating boundaries is itself wrong? Do help me. Thanks a lot!
Answer by agilanbtdw · Nov 18, 2017 at 12:39 PM
Found out a way by myself. Posting my approach just in case someone else is facing a similar problem and also to validate my approach. Upon researching, any gameobject that needs a color (Material) has to have a mesh. In my case I just had the edge collider generated through a script. Hence I had to somehow create meshes for those dynamically generated vertices. I searched for ways to procedurally create meshes for a given set of vertices. And it worked,
I am still looking for ways to optimize it. Should you need more info, just comment below and I would be happy to share the process. Thank you.
Hey, interested in learning how you did the mesh generation as I'm facing the same challenge right now. Thank you!
Your answer
Follow this Question
Related Questions
Refreshing the Polygon Collider (2D) upon sprite change? 1 Answer
OnCollisionEnter2D is called but the actually collision isn't resolving. 0 Answers
Is there a way to apply a texture to a 2d collider? 1 Answer
Can I generate a sprite for a specific collider? 0 Answers
EdgeCollider2D or BoxCollider2D? 1 Answer