Search Unity

GUI don't render after WaitForEndOfFrame() render

Discussion in 'Immediate Mode GUI (IMGUI)' started by Mufan, Sep 13, 2014.

  1. Mufan

    Mufan

    Joined:
    Aug 11, 2013
    Posts:
    15
    Hello!

    I have this:

    Code (CSharp):
    1.  
    2. IEnumerator Capture() {
    3.         yield return new WaitForEndOfFrame();
    4.  
    5.         RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 24, RenderTextureFormat.ARGB32);
    6.         Camera.main.targetTexture = rt;
    7.  
    8.         Camera.main.Render();
    9.  
    10.         RenderTexture.active = rt;
    11.  
    12.         Texture2D foo = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false);
    13.         foo.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    14.  
    15.         Camera.main.targetTexture = null;
    16.         RenderTexture.active = null;
    17.         Destroy(rt);
    18.     }
    I want to see in result texture "foo" full scene: gameobjects & gui.
    But I see only the gameobjects & gui, which I have placed to the scene in Editor (GUIText for example).
    And I don't see any GUI, which created runtime in my OnGUI() methods.

    What am I doing wrong?

    Thanks!