public void OnRemoved(int i) { PolygonalPoint point = points[i]; onLosePoint.Invoke(point); foreach (SpringJoint2D s in GetComponents <SpringJoint2D>()) { if (s.connectedBody.gameObject == point.gameObject) { Destroy(s); break; } } }
public void AddPoint() { Vector3 nPos = (points[0].transform.position + points[sides - 1].transform.position) / 2; PolygonalPoint point = Instantiate(pointObject).GetComponent <PolygonalPoint>(); point.position = sides; points.Add(point); AddSpringyToPoint(sides); sides += 1; point.transform.position = nPos; point.transform.parent = transform; point.body = this; SpringJoint2D sJoint = point.GetComponent <SpringJoint2D>(); sJoint.distance = length; sJoint.connectedBody = points[sides - 2].GetComponent <Rigidbody2D>(); points[0].GetComponent <SpringJoint2D>().connectedBody = point.GetComponent <Rigidbody2D>(); }