Search Unity

Capturing Screen through two cameras

Discussion in 'Scripting' started by KarlKarl2000, Apr 30, 2019.

  1. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    606
    Hi guys,

    Anyone have suggestions on how to screenshot the game at runtime, with 2 cameras? I have one showing the main game and a second camera for the UI elements. Is there a way to composite the two at runtime into one screenshot PNG image?

    Below is the code to get a screencapture from one camera, but I'm stumped on how to get it from 2 cameras.

    Thanks for the help!

    Code (CSharp):
    1. Texture2D _sShotTexture2d = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
    2. _mainCamera.Render();
    3. RenderTexture.active = _mainCamera.targetTexture;
    4. _sShotTexture2d.ReadPixels(new Rect(0, 0, _sShotWidth, _sShotHeight), 0, 0);
    5. byte[] _bytes = _sShotTexture2d.EncodeToPNG();
    6. _fileNameString = SnapShotName();
    7. System.IO.File.WriteAllBytes(_fileNameString, _bytes);
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836