From: http://forum.unity3d.com/threads/227196-Boolean-Mesh-Project
I am using the script to generate a gameobject at runtime and I’m attempting to alter it to allow more than two operand (eventually). After the first two operation I get my custom game object, but it has no mesh collider in the unity window that I can see. Meaning I cant get the meshcollider to perform the second operand.
I’m trying to either:
1- confirm that a meshcollider is generated for the new gameObject at runtime?
2- determine how to access dynamic meshcollider from new gameObject.
Appreciate any help.
-Dustin
A mesh collider is nothing but a pointer to a mesh.
you may access a mesh at any point in time using MeshFilter.sharedMesh, or MeshCollider.sharedMesh. Furthermore, you can access it via the MeshFilter.mesh variable.
//Confirming a mesh collider is generated:
(gameObject.GetComponent<MeshCollider>().sharedMesh == null) // is if the mesh does not even exist.
(gameObject.GetComponent<MeshCollider>().sharedMesh.vertices.length > 0) // if the mesh has vertices, if it doesn't it wasn't created.
(gameObject.GetComponent<MeshFilter>().mesh == null) // is if the mesh does not even exist.
(gameObject.GetComponent<MeshFilter>().sharedMesh == null) // is if the mesh does not even exist.
(gameObject.GetComponent<MeshFilter>().mesh.vertices.length > 0) // if the mesh has vertices, if it doesn't it wasn't created.
//Accessing a mesh collider's mesh:
(gameObject.GetComponent<MeshCollider>().sharedMesh.vertices // vertices of the mesh collider.
(gameObject.GetComponent<MeshCollider>().sharedMesh.triangles // face index's of the mesh collider.
(gameObject.GetComponent<MeshCollider>().sharedMesh.uv // UV coordiantes of the mesh collider.
(gameObject.GetComponent<MeshCollider>().sharedMesh.normals // Normals of the mesh collider.