title: Merging two different texture into one in unity3d
body: <p>i am trying to merge two textures into one in unity 
  the first texture is from a <code>webcamTexture</code>
  the second is from a sprite using : <code>gameobject.getComponent&lt;SpriteRenderer&gt;().sprite.texture as Texture2D</code></p>
  
  <p>I'm having problem in writing the function this is what i did so far :</p>
  
  <pre><code>public static Texture2D CombineTextures(GameObject obj, Texture2D background, Texture2D TodrawLogo)
  {
      Vector3 v = obj.transform.position;// obj is TodrawLogo gameobject
      int width = TodrawLogo.width;
      int height = TodrawLogo.height;
      for (int x =(int)v.x; x &lt; width; x++){
          background.SetPixel(x,(int)v.y,TodrawLogo.GetPixel(x,(int)v.y));
      }
      background.Apply();
      return background;
  }
  </code></pre>
  
  <p>this what i am trying to do : </p>
  
  <p>WebcamTexture
  <img src="https://i.stack.imgur.com/hC5IZ.png" alt="enter image description here"></p>
  
  <p>the result Texture should be like this 
  <img src="https://i.stack.imgur.com/nnUTs.png" alt="enter image description here"></p>
  
  <p>the webcamTexture is a <code>3dplane</code> and the logo is a <code>single sprite</code>
  but sadly my function doesn't work 
  does anyone know how to fix this 
  I know that i should find the exact coordinate of the <code>todraw image</code> and set the pixels but i can't figure out how </p>
  
  <p>Much appreciation </p>
  
  <p>EDIT:</p>
  
  <p>i tried to use  @nexx code :</p>
  
  <pre><code>public static Texture2D CombineTexture(Texture2D background, Texture2D TodrawLogo)
  {
  
    int width = TodrawLogo.width;
    int height = TodrawLogo.height;
  
    int backWidth = background.width;
    int backHeight = background.height;
  // bottom right corner
  int startX = backWidth - width;
  int startY = backHeight - height;
  
  // loop through texture
  int y = 0;
  while (y &lt; backHeight) {
      int x = 0;
      while (x &lt; backWidth) {
          // set normal pixels
          background.SetPixel(x,y,background.GetPixel(x,y));
          // if we are at bottom right apply logo 
          //TODO also check alpha, if there is no alpha apply it!
          if(x &gt;= startX &amp;&amp; y &lt; backHeight- startY)
              background.SetPixel(x,y,TodrawLogo.GetPixel(x-startX,y-startY));
          ++x;
      }
      ++y;
  }
  background.Apply();
  return background;
   }
  </code></pre>
  
  <p>but this is the resulting image i get :
  <img src="https://i.stack.imgur.com/vZTEk.png" alt="enter image description here"></p>
  
  <p>i am stuck at this can someone please tell me what am i doing wrong ?</p>