change object mesh with script

I want to change the Mesh of an object in-game. I have 5 meshes and I want one object where 5 different buttons would switch to the different meshes. the mesh position stays the same. this should also change the mesh collision for the rigid body.
what command can I use?

Depends on whether you have a MeshFIlter component or a SkinnedMeshRenderer component. Figure out which one you are using and then try this:

  1. Put your blend file or other 3d file in your /Resources folder. Create one if you need to.

  2. Use this script. Substitute MeshFilter with SkinnedMeshRenderer depending on which component is attached to your GameObject.

    public GameObject yourGameObject; //assign your gameobject from the inspector here
    MeshFilter yourMesh;

    yourMesh = yourGameObject.GetComponent();
    yourMesh.sharedMesh = Resources.Load(“your mesh name here”);

If you also want to change the material color, you can use:

yourMesh.GetComponent<Renderer>().material.color = new Color(r,g,b,a);