Hello people, novice question.
I need to scale (uniform) a polygoncollider2d generated from a sprite mask.
I want to do this for copy the collider to another gameobject what dont have the same scale as the original.
this is the script what Im using for generate the 2dcollider:
public void Runthis()
{
if (gameObject.GetComponent<PolygonCollider2D>() == null)
{
Polygon2D = gameObject.GetComponentInChildren<PolygonCollider2D>();
}
else
{
Polygon2D = gameObject.GetComponent<PolygonCollider2D>();
}
if (gameObject.GetComponent<SpriteMask>().sprite == null)
{
Sprite = gameObject.GetComponentInChildren<SpriteMask>().sprite;
}
else
{
Sprite = gameObject.GetComponent<SpriteMask>().sprite;
}
for (int i = 0; i < Polygon2D.pathCount; i++) Polygon2D.pathCount = 0;
Polygon2D.pathCount = Sprite.GetPhysicsShapeCount();
List<Vector2> path = new List<Vector2>();
for (int i = 0; i < Polygon2D.pathCount; i++)
{
path.Clear();
Sprite.GetPhysicsShape(i, path);
Polygon2D.SetPath(i, path.ToArray());
}
}
any guidance how can be the script syntax?, thanks.
I think can scale the vector2 before to apply to the collider, but not sure how do it.
PD: Want to scale the polygoncollider without change the scale of the new target gameobject