- Home /
Black RenderTexture when used with GUI.DrawTexture
Hey all,
I'm trying to use a RenderTexture to draw a second camera's view in my character select screen. I've followed the instructions laid out by Unity for setting up a RenderTexture, that is:
-Create a new RenderTexture
-Create a second camera
-Assign the RenderTexture to the second camera
But when I try to use the RenderTexture as the image for a GUI.DrawTexture object, it just appears as a black rectangle in my menu.
That being said, I applied the RenderTexture to a cube gameobject, and it still appeared black there, too.
Any ideas?
Edit:
There's a lot that went in to my GUI, but here's the relevant code:
using UnityEngine; using System.Collections;
public class MainMenu : MonoBehaviour {
...
public RenderTexture maleCam;
void RenderCharSelect(){
//BG Image
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), charSelect, ScaleMode.StretchToFill, true, 0f);
//RenderTexture GUI Texture
GUI.DrawTexture (new Rect ((17.00f/100f)*xPos,(27.00f/100f)*yPos,(30.0f/100f)*xPos,(41.0f/100f)*yPos),maleCam);
We shall see your code to tell where you were mistaken. But, maybe, you don't apply your texture into memory.
Sure, I've edited it to include the RenderTexture code, but it's not much. How do I apply the texture in to memory? Is that using done by using RenderTexture.active=rt; ?
Oh, I have been able to get the RenderTexture to show something other than black in my menu, but it seems to happen randomly. What happens is, it shows the current menu screen, but in the GUI texture that I've set to use the second camera's view. It seems to be using the main camera's view, even though I've more than triple checked to make sure that the render texture was set to the second camera.