Realtime mesh triangles do not appear depending on camera angle

I am creating a mesh that is a cube with two vertices of the same edge removed. This makes it a prism. The problem is that after clearing the mesh then setting the new vertices and triangles, only half of the triangles appear at the same time. The other half appear when changing the scene camera’s angle. Here are some screenshots to show the problem :

156885-screenshot-2020-04-17-at-123432.png

156886-screenshot-2020-04-17-at-123442.png

As you can see the triangle to the right does not appear in the first screenshot but appears through a missing triangle in the second screenshot. Here is my code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class createPrism : MonoBehaviour {

    public Mesh mesh;

	void Start () {
        mesh = GetComponent<MeshFilter>().mesh;
        Vector3[] vertices = {
            new Vector3(-0.5f,-0.5f,-0.5f),
            new Vector3(0.5f,-0.5f,-0.5f),
            new Vector3(-0.5f,0.5f,-0.5f),
            new Vector3(0.5f,0.5f,-0.5f),
            new Vector3(-0.5f,-0.5f,0.5f),
            new Vector3(0.5f,-0.5f,0.5f)
        };

        int[] triangles = {
            0,1,2,
            1,2,3,
            0,1,4,
            1,4,5,
            2,3,4,
            3,4,5,
            1,5,3,
            0,2,4
        };

        mesh.Clear();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
	}
}

This is probably an easy fix but I couldn’t find anything like this online.

Triangles have a direction they face. They have a front side (which is visible) and a back side (which is not visible). The side depends on the winding order of your vertices. In Unity by default a clockwise winding denotes the front face. If the winding order is counter clockwise it will be a backface and (due to backface culling) not visible.

I did not go through your triangle list to figure out which one you have inverted. However note that in order to change the winding order you just have to swap any two vertices of a triangle. I would start by first adding comments to your vertices to keep track which one is which. I highly recommend you create a drawing of your mesh on paper and label your vertices. Then it’s much easier to figure out the correct winding order. I also recommend to add comments to each triangle tripple to know which side / face it belongs to. Your prism has 3 quads (6 tirangles) and 2 triangle faces.