title: Assigning different materials to different meshes on the same object
body: <p>I initially had a function that created a rectangular mesh given a specific height/width:</p>
  <pre><code>void BoxMesh(float width, float height)
  {
      MeshFilter mf = GetComponent&lt;MeshFilter&gt;();
      Mesh mesh = new Mesh();
      mf.mesh = mesh;
  
      //Verticies
      Vector3[] verticies = new Vector3[4]
      {
          new Vector3(0,0,0), new Vector3(0, height, 0), new Vector3(width, height, 0), new Vector3(width, 0, 0)
      };
  
      //Triangles
      int[] tri = new int[6];
  
      tri[0] = 0;
      tri[1] = 1;
      tri[2] = 3;
  
      tri[3] = 1;
      tri[4] = 2;
      tri[5] = 3;
  
      //normals
      
      Vector3[] normals = new Vector3[4];
  
      normals[0] = -Vector3.forward;
      normals[1] = -Vector3.forward;
      normals[2] = -Vector3.forward;
      normals[3] = -Vector3.forward;
  
      //UVs
      
      Vector2[] uv = new Vector2[4];
      
      uv[0] = new Vector2(0, 0);
      uv[1] = new Vector2(0, 1);
      uv[2] = new Vector2(1, 1);
      uv[3] = new Vector2(1, 0);
      
      
  
      //initialise
      mesh.vertices = verticies;
      mesh.triangles = tri;
      mesh.normals = normals;
      mesh.uv = uv;
  
      //setting up collider
      polyCollider.pathCount = 1;
  
      Vector2[] path = new Vector2[4]
      {
          new Vector2(0,0), new Vector2(0, height), new Vector2(width, height), new Vector2(width, 0)
      };
  
      polyCollider.SetPath(0, path);
  
  }
  </code></pre>
  <p>I then decided I wanted this mesh to have an outline so I edited the function so it is now:</p>
  <pre><code>void BoxMesh(float width, float height, float OLwidth)
  {
      MeshFilter mf = GetComponent&lt;MeshFilter&gt;();
      Mesh mesh = new Mesh();
      mf.mesh = mesh;
  
      MeshFilter mfOL = GetComponent&lt;MeshFilter&gt;();
      Mesh meshOL = new Mesh();
      mfOL.mesh = meshOL;
  
      //Verticies
      Vector3[] verticies = new Vector3[4]
      {
          new Vector3(0,0,0), new Vector3(0, height, 0), new Vector3(width, height, 0), new Vector3(width, 0, 0)
      };
  
      //Verticies Outline
      Vector3[] verticiesOL = new Vector3[4]
      {
          new Vector3(-OLwidth,-OLwidth,0), new Vector3(-OLwidth, height + OLwidth, 0), new Vector3(width + OLwidth, height + OLwidth, 0), new Vector3(width + OLwidth, -OLwidth, 0)
      };
  
      //Triangles
      int[] tri = new int[6];
  
      tri[0] = 0;
      tri[1] = 1;
      tri[2] = 3;
  
      tri[3] = 1;
      tri[4] = 2;
      tri[5] = 3;
  
      //normals
      
      Vector3[] normals = new Vector3[4];
  
      normals[0] = -Vector3.forward;
      normals[1] = -Vector3.forward;
      normals[2] = -Vector3.forward;
      normals[3] = -Vector3.forward;
  
      //UVs
      
      Vector2[] uv = new Vector2[4];
      
      uv[0] = new Vector2(0, 0);
      uv[1] = new Vector2(0, 1);
      uv[2] = new Vector2(1, 1);
      uv[3] = new Vector2(1, 0);
      
      //initialise
      mesh.vertices = verticies;
      mesh.triangles = tri;
      mesh.normals = normals;
      mesh.uv = uv;
      
      meshOL.vertices = verticiesOL;
      meshOL.triangles = tri;
      meshOL.normals = normals;
      meshOL.uv = uv;
  
      //setting up collider
      polyCollider.pathCount = 1;
  
      Vector2[] path = new Vector2[4]
      {
          new Vector3(-OLwidth,-OLwidth,0), new Vector3(-OLwidth, height + OLwidth, 0), new Vector3(width + OLwidth, height + OLwidth, 0), new Vector3(width + OLwidth, -OLwidth, 0)
      };
  
      polyCollider.SetPath(0, path);
  
  }
  </code></pre>
  <p>So i now have two meshes one outside the other. However I want the one on the outside to have a different material: so it looks like an outline.</p>
  <p><a href="https://i.stack.imgur.com/JmUzj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JmUzj.png" alt="" /></a></p>
  <p>I have these two materials in my mesh renderer, so how would I go about assigning one material to the outer mesh, and another to the inner mesh.</p>