How to add a MeshCollider to this object(triangle) that I made?

void Start() {

gameObject.rigidbody.useGravity= false;
    Mesh mesh = GetComponent<MeshFilter>().mesh;
    mesh.vertices = new Vector3[] {new Vector3(0, 0, 0), new Vector3(0.25f, 0, 0.75f), new Vector3(0.75f, 0, 0.25f)};
    mesh.uv = new Vector2[] {new Vector2(0, 0), new Vector2(0.25f, 0.75f), new Vector2(0.75f, 0.25f)};
    mesh.triangles = new int[] {0, 1, 2};


I want to add collider to it, for instance if an object is falling from the sky, along it’s Y axis, and it hits this new object to stop on it. Of course now it just passes through it. I understand i have to use MeshCollider, but I haven’t used it before, thus I really don’t know how? Thank you for your help.

Component> Physics> Mesh collider.

I agree with @Fattie, other colliders will probably do the job just as well and are much faster. If you wanted the flat sides of a collider, then a BoxCollider would do. You could add the following to the end of the Start() script above:


And the BoxCollider should size itself to encompass your triangle. If you really want a MeshCollider, your mesh will need to be more than just a triangle I believe since it is infinitely thin and your RigidBody will attempt to compute the inertial tensor based on the matching infinitely thin MeshCollider and fail - so you’ll get an error in that case.