本文整理汇总了C#中UnityEngine.PolygonCollider2D.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# PolygonCollider2D.GetComponent方法的具体用法?C# PolygonCollider2D.GetComponent怎么用?C# PolygonCollider2D.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.PolygonCollider2D
的用法示例。
在下文中一共展示了PolygonCollider2D.GetComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMesh
public void CreateMesh(PolygonCollider2D col)
{
GameObject temp = col.gameObject;
MeshFilter meshFilter;
MeshRenderer meshRenderer;
if (temp.GetComponent<MeshFilter>() != null)
meshFilter = temp.GetComponent<MeshFilter>();
else
meshFilter = temp.AddComponent<MeshFilter>();
if (col.GetComponent<MeshRenderer>() != null)
meshRenderer = temp.GetComponent<MeshRenderer>();
else
meshRenderer = temp.AddComponent<MeshRenderer>();
Vector3[] points = new Vector3[col.points.Length];
for(int i = 0; i < col.points.Length; i++)
{
points[i] = new Vector3(col.points[i].x, col.points[i].y, -1);
}
int[] triangles = new int[(col.points.Length - 1) * 3];
int lastNum = 0;
for(int i = 0; i < ((triangles.Length - 1) / 3); i++)
{
if(i == 0)
{
triangles[0] = 0;
triangles[1] = 1;
triangles[2] = 2;
lastNum = 2;
}
else
{
triangles[i * 3] = lastNum;
triangles[i * 3 + 1] = lastNum + 1;
triangles[i * 3 + 2] = 0;
lastNum++;
}
}
Mesh mesh = new Mesh();
mesh.Clear();
mesh.vertices = points;
mesh.triangles = triangles;// new int[] { 0, 1, 2, 2, 3, 0, 3, 4, 0, 0, 0, 0 };//triangles;
meshFilter.mesh = mesh;
Material mat = new Material(Shader.Find("Sprites/Default"));
mat.color = new Color(0, 0.66f, 0, 0.4f);
meshRenderer.material = mat;
}