将代码脚本挂在雷达数据图上面后,代码中的float[] arr数组是雷达图要展示的数据类型个数,每点击一次按钮,雷达的每一个数据的数值会在一定范围内随机转换
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Creat_Ont : MaskableGraphic
{
public float[] arr;
public Button b1;
protected override void Start()
{
b1.onClick.AddListener(() =>
{
SetAllDirty();
for (int i = 0; i < arr.Length; i++)
{
arr[i] = Random.Range(0, 82);
}
});
}
protected override void OnPopulateMesh(VertexHelper vh)
{
if (arr.Length<3)
{
base.OnPopulateMesh(vh);
return;
}
vh.Clear();
float ang = 2 * Mathf.PI / arr.Length;
vh.AddVert(Vector3.zero,color,Vector2.zero);
for (int i = 0; i < arr.Length; i++)
{
float x = Mathf.Sin(ang * i) * arr[i];
float y = Mathf.Cos(ang * i) * arr[i];
vh.AddVert(new Vector3(x,y,0),color,Vector2.zero);
if (i==0)
{
vh.AddTriangle(0, arr.Length, 1);
}
else
{
vh.AddTriangle(0, i, i + 1);
}
}
}
}