面板上看上去是靠Points来规定形状和范围的。
但是自己用代码测试过:
weaponPolygonCollider2D[i].points[l].x *= computerEffect;
weaponPolygonCollider2D[i].points[l].y *= computerEffect;
当computerEffect =1.2的时候,最终的Points并没有因此改变,就像上面说的不可编辑信息。
这时候就要采用weaponPolygonCollider2D[i].SetPath。
PolygonCollider2D.SetPath(int index,Vector2[] points)
路径是定义多边形轮廓线的点之间的线段连续循环。由于多边形可以有孔和不连续的部分,那它形状不一定是由单一路径定义的。[1]所以上面的Vector2是数组。
采用weaponPolygonCollider2D[i].SetPath的代码:
private void ComputerEffect()
{
weaponTransform = this.transform.parent.parent.Find("Weapon");
weaponPolygonCollider2D = weaponTransform.GetComponentsInChildren<PolygonCollider2D>();
for (int i = 0; i < weaponPolygonCollider2D.Length; i++)
{
(x, y) = scriptShip.GetPolygonCollider2DPoints(weaponPolygonCollider2D[i]);
newPoint = new Vector2[weaponPolygonCollider2D[i].points.Length];
for (int l = 0; l < weaponPolygonCollider2D[i].points.Length; l++)
{
float x1= weaponPolygonCollider2D[i].points[l].x *computerEffect;
float y1= weaponPolygonCollider2D[i].points[l].y *computerEffect;
newPoint[l] = new Vector2(x1, y1);
}
weaponPolygonCollider2D[i].SetPath(0, newPoint);
}
}
面板已经发生变化,数值从30变成了36。
[1] Unity5 中文 API 手册.PolygonCollider2D.SetPath 设置路径
2019-12-18/2023-1-5
https://www.wenjiangs.com/doc/unity5-polygoncollider2d-setpath