File size: 828 Bytes
58c78a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using UnityEngine;

public class BoundingCircle : MonoBehaviour
{
    public LineRenderer lineRenderer;
    public Color color;
    public float width;
    public int numSegments;

    void Start()
    {
        lineRenderer.startColor = color;
        lineRenderer.endColor = color;
        lineRenderer.startWidth = width;
        lineRenderer.endWidth = width;
    }

    public void Set(bool active, Vector3 position, float radius)
    {
        gameObject.SetActive(active);
        lineRenderer.positionCount = numSegments;
        for (var i = 0; i < numSegments; i++)
        {
            var theta = 2 * Mathf.PI * i / (float)numSegments;
            lineRenderer.SetPosition(i, position + radius * new Vector3(Mathf.Cos(theta), Mathf.Sin(theta), 0));
        }
        lineRenderer.loop = true;
    }
}