该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
源码
//画圆(其中一个圆)
using UnityEngine;
public class CircleRenderer : MonoBehaviour
{
private LineRenderer lineRenderer;
private void Start()
{
lineRenderer = GetComponent();
deltaAngle = 360 / pointNum;
posArray = new Vector3[pointNum + 1];
float angle = 0;
for (int i = 0; i < pointNum; i++)
{
float x = R * Mathf.Cos((90 - angle) / 180 * Mathf.PI);
float y = R * Mathf.Sin((90 - angle) / 180 * Mathf.PI);
posArray[i] = new Vector3(x, y, 0);
angle += deltaAngle;
}
posArray[pointNum] = new Vector3(0, R, 0);
}
//画圆
[Header("圆上取的点数")]
public int pointNum = 360;
[Header("该⚪的半径")]
public int R = 5;
private float deltaAngle;
public Vector3[] posArray;
private void Update()
{
lineRenderer.SetPositions(posArray);
}
}
//雷达基线
using UnityEngine;
public class Line : MonoBehaviour
{
private LineRenderer lineRenderer;
private void Start()
{
line[0] = Vector3.zero;
lineRenderer = GetComponent();
}
//画线
[Header("角速度")]
public float angularSpeed;
[Header("最大半径")]
public float R;
private Vector3[] line = new Vector3[2];
private float angle;
private void Update()
{
float x = R * Mathf.Cos((90 - angle) / 180 * Mathf.PI);
float y = R * Mathf.Sin((90 - angle) / 180 * Mathf.PI);
line[1] = new Vector3(x, y, 0);
lineRenderer.SetPositions(line);
angle += angularSpeed * Time.deltaTime;
if (angle > 360) angle -= 360;
}
}