ソースコード
using UnityEngine;
public sealed class CircleLineRenderer : MonoBehaviour
{
[SerializeField] private LineRenderer m_lineRenderer;
[SerializeField] private float m_radius;
[SerializeField] private float m_lineWidth;
private void Reset()
{
m_lineRenderer = GetComponent<LineRenderer>();
}
private void Awake()
{
InitLineRenderer();
}
private void InitLineRenderer()
{
var segments = 360;
m_lineRenderer.startWidth = m_lineWidth;
m_lineRenderer.endWidth = m_lineWidth;
m_lineRenderer.positionCount = segments;
m_lineRenderer.loop = true;
m_lineRenderer.useWorldSpace = false;
var points = new Vector3[ segments ];
for ( var i = 0; i < segments; i++ )
{
var rad = Mathf.Deg2Rad * ( i * 360f / segments );
var x = Mathf.Sin( rad ) * m_radius;
var y = Mathf.Cos( rad ) * m_radius;
points[ i ] = new Vector3( x, y, 0 );
}
m_lineRenderer.SetPositions( points );
}
}
関連記事