How to delete a element from mesh rendered and mesh collider.

I want to actually delete the element not just its shader using script so it can happen on collision.


Get a reference to the component and edit the element you want. I’m not sure what element you mean?

// Remove the material, or you can access the array of materials
// and remove specific materials only
gameObject.GetComponent<MeshRenderer>().material = null;

// Remove the mesh object so it is invisible
gameObject.GetComponent<MeshFilter>().mesh = null;

// Remove the mesh collider material
gameObject.GetComponent<MeshCollider>().material= null;