using UnityEngine;
using UnityEngine.UI;
public class DrawLoad : Graphic
{
protected override void OnPopulateMesh(VertexHelper vh)
{
//==========================
float r = rectTransform.rect.height / 2.0f;
//float widthFactor = (rectTransform.rect.width / 2.0f) - r;
float y = r;
float x = 0.0f;
int t = 20; // t = total vertices
float a = 360.0f / (t-1); // angle delta/differences between each vertex
float aC = 0.0f; // incrementing angles from 0 --> 360
int maxi = t - 1;
Vector2[] vtR = new Vector2[t];
UIVertex[] uivR = new UIVertex[t];
vh.Clear();
for (int i = 0; i <= maxi; i++)
{
y = r * Mathf.Cos(Mathf.Deg2Rad * aC);
x = r * Mathf.Sin(Mathf.Deg2Rad * aC);
vtR *= new Vector2(x, y);*
-
aC += a;*
_ uivR = UIVertex.simpleVert;_
uivR_.position = vtR*;//0,0*
uivR*.color = Color.green;
vh.AddVert(uivR);
}*_
* // ======== add center point ========*
* Vector2 center = new Vector2(0.0f, 0.0f);*
* UIVertex c = UIVertex.simpleVert;*
* c.position = center;//0,0*
* c.color = Color.green;*
* vh.AddVert(c);*
* for (int i = 0; i <= maxi; i++)*
* {*
* vh.AddTriangle(t, i, i + 1);// use indexes, don’t use count, start from 0*
* }*
* for (int i = 0; i < uivR.Length; i++)*
* {*
_ uivR*.color = Color.green;
vh.SetUIVertex(uivR,i);
}*_
* }*
}
Hi, I wish to change the color dynamically of each assigned triangles.
I have these code modified from Unity documentation and I tried the SetUIVertex method but it doesn’t seems to work. This is actually a circle made up from every piece of triangles. What is the proper way to redraw the vertices.
I want to make it in MonoBehavior.Update(). Any helps would be greatly appreciated. Thanks.