Many RTS games display distances (range attack, moving distance, sight, and so on) by drawing a circle around the selected unit. If the terrain is flat, this can be done simply by stretching a quad with the texture of a circle. If that's not the case, the quad will most likely be clipped behind a hill or another piece of geometry. This recipe will show you how to create a shader that allows you to draw circles around an object of arbitrary complexity. If you want to be able to move or animate your circle, we will need both a shader and C# script. The following image shows an example of drawing a circle in a hilly region using a shader:
Despite working with every piece of geometry, this technique is oriented to terrains. Hence, the first step is setting up a terrain in Unity.
Let's start by creating a new shader called
RadiusShader
and the respective material,Radius
.Have the character for your object ready; we will draw a circle around it...