Hello,
currently I’m using Gizmos.DrawWireSphere to show the circumference of my Physics.Overlapsphere. The problem is I don’t want to just show the radius for debugging and I want the player to be able to see it. So, how would I go about drawing this circumference in game?
After doing some research I found a line renderer would do the job I needed.
Here’s the solution for any passers by:
float theta_scale = 0.01f; //Set lower to add more points
int size; //Total number of points in circle
float radius = 2f;
LineRenderer lineRenderer;
void Awake()
{
float sizeValue = (2.0f * Mathf.PI) / theta_scale;
size = (int)sizeValue;
size++;
lineRenderer = gameObject.AddComponent<LineRenderer>();
lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
lineRenderer.SetWidth(0.02f, 0.02f); //thickness of line
lineRenderer.SetVertexCount(size);
}
void Update()
{
Vector3 pos;
float theta = 0f;
for (int i = 0; i < size; i++)
{
theta += (2.0f * Mathf.PI * theta_scale);
float x = radius * Mathf.Cos(theta);
float y = radius * Mathf.Sin(theta);
x += gameObject.transform.position.x;
y += gameObject.transform.position.y;
pos = new Vector3(x, y, 0);
lineRenderer.SetPosition(i, pos);
}
}