應用:
1.可視化
2.設置圓形區域
/* ***********************************************
* Discribe:Use LineRenderer to DrawCircle
* Author:Wilson
* CreateTime:2020-06-30 09:15:53
* Edition:1.0
* ************************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(LineRenderer))]
public class DrawCircle : MonoBehaviour
{
public float _y = .5f;
public int angle = 12;
public float radius = 3f;
public float width = .5f;
LineRenderer lineRenderer;
void Awake()
{
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.endWidth = lineRenderer.startWidth = width;
}
void Update()
{
_DrawCircle();
}
void _DrawCircle()
{
angle = Mathf.Clamp(angle, 2, 60);
lineRenderer.positionCount = angle;
for (int i = 0; i < angle; i++)
{
float x = radius * Mathf.Cos(i * (2 * Mathf.PI / angle));
float z = radius * Mathf.Sin(i * (2 * Mathf.PI / angle));
lineRenderer.SetPosition(i, new Vector3(x, _y, z));
}
}
}