- Home /
Trouble with drawing a RenderTexture in the GUI
Hello, I'm trying to use a RenderTexture to draw a camera onto my GUI using a GUI.DrawTexture call. I haven't found any explanation of how to do this, so I'm trying to figure it out on my own and it's not quite working. Here's how I'm doing it...
1) Followed the steps listed here to created the RenderTexture and attach it to a plane object in my scene, named "FinalSceneTextureBox"
2) In my OnGUI() method, I'm trying to access the "FinalScenTextureBox" texture, that is generated by the RenderTexture object, and draw it using a GUI.DrawTexture() call. Here's the code...
Texture activeCameraTexture = finalSceneTextureBox.renderer.materials[0].mainTexture;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height/2 + buttonHeight), activeCameraTexture);
The camera that I'm trying to render to my GUI has text in it and that text is slightly visible in my GUI where I'm trying to draw the texture, which tells me that my approach is kinda working, but everything else seems transparent. My questions are...
1) Why isn't this approach working?
2) Is there a better way to do this?
Thanks so much in advance for your help!