Hello!
Is it possible to create a polygon collider on a complex shape (it has a mesh/mesh renderer/edge colliders) based on points of actual edge colliders?
I made a simple script but it is not working, i tried to get edge colliders points as an array and add them to a new added polygon collider… Of course it doesn’t work.
using System.Collections;
public class EdgeToPolygon : MonoBehaviour {
private PolygonCollider2D myCollider;
private Vector2[] tempArray;
// Update is called once per frame
void Start (){
EdgeCollider2D testEdge = GetComponent<EdgeCollider2D>();
Vector2[] tempArray = testEdge.points;
}
void Update () {
if (Input.GetKeyDown("space"))
gameObject.AddComponent <PolygonCollider2D>();
if (Input.GetKeyDown("enter"))
myCollider = gameObject.GetComponent<PolygonCollider2D>();
myCollider.points = tempArray;
}
}
Any tips? Each kind of help is really appreciated!
Thanks,
Kaem