I´m loading a prefab from the Resource folder.
This prefab has a Canvas with the property Screen Space - Camera.
I want to add from script the Render Camera once this component is loaded (so in start function). The camera object that I want to add is already on the scene.
How to do it? Something like FindByTag?
If it’s the main camera, you can access it using Camera.main
. If it’s not, usually a public/serialized field comes in handy:
public Camera canvasCamera;
public Canvas canvasPrefab;
public void CreateDatCanvas()
{
var instantiatedCanvas = Instantiate(canvasPrefab);
instantiatedCanvas.worldCamera = canvasCamera;
}
Hi FlaSh-G,
I already load the prefab on the scene, what I want to do is to assign the Render Texture to something that is not in the same prefab (the camera in the scene).
It seems that I can´t drag and drop the camera to the public canvasCamera because is not in the same prefab