I created a render texture named GUICameraRenderTexture
This is a screenshot of the player camera:
I have assigned the new GUICameraRenderTexture to the target texture:
Then, at the bottom of the hierarchy, I have a main menu> Camera:
The new camera for which I've changed Clear Flags in Don Clear and Culling Mask in Nothing:
Then there is a Canvas area in which the Canvas render mode is set to "Screen Space Overlay"
Lastly, the raw image I assigned to the GUICameraRenderTexture texture:
I want to start the game with the player camera and then use the Escape key to switch to the main menu of the GUI camera.
Screenshot when I disable the main menu GUI camera:
Then I added a script to the main menu object:
public class Switch : MonoBehaviour
public GameObject() cameras;
public RenderTexture guiCameraRenderTexture;
// Start is called before the first frame update
// Update is called once per frame
var cam0 = cameras(0).GetComponent();
cam0.targetTexture = guiCameraRenderTexture;
In the editor I have disabled the new main menu GUI camera and its children and enabled the player camera without the GUICameraRenderTexture. The target texture is null at startup.
If I press the Escape key while the game is running, the preview camera will be displayed, as will the player camera, not the main menu GUI camera:
On the escape key it should bring the main menu as in the first screenshot here. If I make the changes and remove the texturiel and activate the GUI camera, it works, but it does not work with the script.
It shows the player camera both in the preview (raw image) and in the GUI camera.
The goal is to press the escape key to get to the main menu. The GUI main menu camera should be black and the player camera should be displayed in the preview raw image.