using UnityEngine;
using System.Collections;
[RequireComponent(typeof(LineRenderer))]
public class DrawCircle : MonoBehaviour
{
[Range(0, 50)]
public int segments = 50;
[Range(0, 5)]
public float xradius = 5;
[Range(0, 5)]
public float yradius = 5;
LineRenderer line;
void Start()
{
line = gameObject.GetComponent<LineRenderer>();
line.positionCount = segments + 1;
line.useWorldSpace = false;
CreatePoints();
}
void Update()
{
CreatePoints();
}
void CreatePoints()
{
float x;
float y;
float z;
float angle = 20f;
for (int i = 0; i < (segments + 1); i++)
{
x = Mathf.Sin(Mathf.Deg2Rad * angle) * xradius;
z = Mathf.Cos(Mathf.Deg2Rad * angle) * yradius;
line.SetPosition(i, new Vector3(x, 0, z));
angle += (360f / segments + 1);
}
}
}
And i attached this script to a gameobject a cube.
The cube have a linerenderer component.
In the Inspector on the right when i change the color from white to red for example it’s not changing the circle color. The circle color is pink by default. I can add a material but then it will make some other mixed color. If i add a red material the circle will be kind of brown.
Another problem is if i change the circle thickness in the Inspector moving down the red line the circle will looks like a bit above ground(terrain). Then i can move the cube a bit down but then the cube will be inside the terrain:
Both problems: How to change the circle color ? And how to change the circle height position/to keep the circle height position to be always on ground.

