Example #1
0
        public static ConvexMesh AddConvexMesh(Vector3 position, IList <Vector3> vertices, Space space, Material meshMatt = null, bool attachRigidbody = true)
        {
            GameObject convex = new GameObject();

            if (space == Space.Self)
            {
                convex.transform.position = position;
            }
            else
            {
                Vector3 center = new Vector3();
                for (int i = 0; i < vertices.Count; i++)
                {
                    center += vertices[i];
                }
                convex.transform.position = position + center / vertices.Count;
            }

            ConvexMesh convexComponent = convex.AddComponent <ConvexMesh>();

            convexComponent.Build(vertices, meshMatt);
            if (attachRigidbody)
            {
                convex.AddComponent <Rigidbody2D>();
            }
            return(convexComponent);
        }
Example #2
0
        public static ConvexMesh AddConvexMesh(Vector3 position, Vector3[] vertices, Material meshMat = null, bool attachRigidbody = true)
        {
            GameObject convex = new GameObject();

            convex.transform.position = position;

            ConvexMesh convexComponent = convex.AddComponent <ConvexMesh>();

            convexComponent.Build(vertices, meshMat);
            if (attachRigidbody)
            {
                convex.AddComponent <Rigidbody2D>();
            }
            return(convexComponent);
        }