2
votes

I have two cameras in my scene - one to follow 2D objects and the other for 3D Models (the second camera has other angle of view than first).

I want to create third camera that combines views from that 2 cameras (so, that camera should "see" what the user "see the game"). Is that possbile?

Why I want such a camera? I would like to make a screenshot. I know I can user Application.CaptureScreenshot but it also captures UI elements. Why can't I disable UI elements for a few miliseconds only when screen is captured? Because the effect is ugly (user sees the moment when UI disappears for a while). So my idea is to create third camera that ignores UI layers (but sees exactly what users sees). make render a frame to file and destroy that camera.

My code so far:

private IEnumerator CaptureScreenCoroutine()
{
    // Wait till the last possible moment before screen rendering to hide the UI
    yield return null;

    this.EnableUi(false);

    // Wait for screen rendering to complete
    yield return new WaitForEndOfFrame();

    // Take screenshot 
    Application.CaptureScreenshot("SomeScreenShor.png");
    this.EnableUi(true);    
}
1
Seems more like a Unity specific question. Maybe try the Unity Forum? - Neijwiert
you are welcome here too, @nopeflow - ゴスエン ヘンリ

1 Answers

1
votes

With a Monobehaviour that is attached to the last rendered camera you will need something like this.

void LateUpdate(){
    Texture2D tex = new Texture2D(Screen.width, Screen.height);
    tex.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0);
    tex.Apply();
}

this will dump all pixels on the screen into "tex" then you can do what you will with it. This might cause a hitch depending on the resolution that you are rendering the cameras at.