title: How do I capture a screenshot in Unity3d with a transparent background?
body: <p>I'm trying to capture a screenshot of a gameobject in Unity3D Pro so that it has a transparent background. This script was suggested to me and it works, when connected to the main Camera, as long as the material doesn't have a texture. Then I get a semi transparency appearing on the gameobject as shown in this example. <a href="http://sta.sh/0iwguk5rx61" rel="nofollow">http://sta.sh/0iwguk5rx61</a>. Any help with this would be greatly appreciated.</p>
  
  <pre><code>public int resWidth = 2550; 
  public int resHeight = 3300;
  
  private bool takeHiResShot = false;
  
      public static string ScreenShotName(int width, int height) {
      return string.Format("{0}/screen_{1}x{2}_{3}.png", 
                           Application.dataPath, 
                           width, height, 
                           System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
  }
  
  public void TakeHiResShot() {
      takeHiResShot = true;
  }
  
  void LateUpdate() {
      takeHiResShot |= Input.GetKeyDown("k");
      if (takeHiResShot) 
      {
          RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
          camera.targetTexture = rt;
          Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.ARGB32, false);
          camera.Render();
          RenderTexture.active = rt;
          screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
          camera.targetTexture = null;
          RenderTexture.active = null; 
          Destroy(rt);
          byte[] bytes = screenShot.EncodeToPNG();
          string filename = ScreenShotName(resWidth, resHeight);
  
          System.IO.File.WriteAllBytes(filename, bytes);
          Debug.Log(string.Format("Took screenshot to: {0}", filename));
          Application.OpenURL(filename);
          takeHiResShot = false;
      }
  }
  </code></pre>
  
  <p>sdg</p>