Search Unity

How to draw a circle with a set radius in game view?

Discussion in 'Image Effects' started by AlbertDevelopment, Aug 23, 2021.

  1. AlbertDevelopment

    AlbertDevelopment

    Joined:
    Jul 5, 2020
    Posts:
    1
    Hello. I am working on a tower defense game, and I want to make a support-like tower that increases nearby tower's attacks. The problem? I want to show the player the range of this tower's support ability through a circle.

    In other words, I want this :

    Code (CSharp):
    1. void OnDrawGizmosSelected()
    2.     {
    3.  
    4.         Gizmos.DrawWireSphere(position, range);
    5.  
    6.     }
    but in the game view. Is it possible?
     
  2. Reahreic

    Reahreic

    Joined:
    Mar 23, 2011
    Posts:
    254
    There's several ways to do this and it depends on the style you want. (Ordered by complexity)
    1. You can instantiate one or more a 2D world space SpriteRenderers in your scene at the tower's location.
    2. You can instantiate a UI element onto the main screen space UI Canvas and use Camera.WorldToScreenPoint to place it over the tower.
    3. Have your 3D artist create a single sided ring in their tool of choice and apply a double sided material to it within unity. Then you can instantiate it and scale it at will using unity's transform.
    4. You can dynamically create a 3D Sphere/Ring/Tube/Torus/Cylinder primitive and assign the mesh to an instantiated GameObject's mesh renderer.
    5. Experiment with Unity's Particle System, IIRC I've seen a particle system based forcefield visualization somewhere that looked nice.
    6. You can do some sort of post processing custom shader magic, but that's more work than it's worth IMO.
    Hopefully that helps generate some solution ideas for you.