title: Apply texture in a quad mesh from a texture atlas
body: <p>I'm trying to apply dynamically a texture from a texture atlas to a quad mesh in Unity3D.</p>
  
  <p>When I do the same in a mesh of a cube, the front face works very fine but the other ones get distorted. So I had the idea to use a simple quad and now I'm facing this scenario:</p>
  
  <p><a href="https://i.stack.imgur.com/FSTDZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FSTDZ.png" alt="enter image description here"></a></p>
  
  <p>The image should be displayed like this:</p>
  
  <p><a href="https://i.stack.imgur.com/ScO2h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ScO2h.png" alt="enter image description here"></a></p>
  
  <p>I'm placing the texture by the code below. The math is working fine:</p>
  
  <pre><code>public int offsetX = 0;
  public int offsetY = 0;
  
  private const float offset = 0.0625f; // the rate of each texture square
  
  void Start ()
  {
      Mesh mesh = GetComponent&lt;MeshFilter&gt;().mesh;
  
      Vector2[] UVs = new Vector2[mesh.vertices.Length];
  
      UVs[0] = new Vector2(offsetX * offset, offsetY * offset);
      UVs[1] = new Vector2((offsetX * offset) + offset, offsetY * offset);
      UVs[2] = new Vector2(offsetX * offset, (offsetY * offset) + offset);
      UVs[3] = new Vector2((offsetX * offset) + offset, (offsetY * offset) + offset);
  
      mesh.uv = UVs;
  }
  </code></pre>
  
  <p>What should I do to place the texture in the quad mesh as the image reference?</p>