利用LineRenderer繪製圓

應用:

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));
        }
    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章