Search code examples
c#unity-game-enginecollider

Unity - Display radius range


I would like to use a Sprite (of a circle outline) to display the range of an unit around it. I am using

Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius);

to detect collisions. However, I have no clue what size should my sprite be in order to match the OverlapCircleAll's radius. Maybe the easiest way would be to draw a circle myself ?


Solution

  • The most easy and convinient way would be using a Projector.

    By using a projector you can easily set the texture size in both perspective and orthographic projection, in perspective you can use the projector transform to set this and in orthographic you can set the size via the Orthographic Size property

    For using a projector you need a special shader tho, you can find them online, there are 3 default i think, additive, multiply and light.

    The Light and Multiply projector shaders are contained in the unity standard assets package