Im trying to instantiate Canvas prefabs on running time, and I want the Canvas to have RenderMode ‘Screen Space - Camera’.
Other than that, I have a separate GuiCam (Camera) in the scene, and I want to set it as the renderCamera for the instantiated canvas. I cant seem to find a way that works for me, to do this from code.
I’m using C#.
Q: How do you set renderCamera on a Canvas from code? Do you have any suggestions?
Oki I’ll try. There is a good chance, that there is something fundamental I’m just not aware of. The following code is attached to the canvas I’m instantiating runtime.
The canvas has RenderMode ‘Screen Space - Camera’, and I want to set the renderCamera for this canvas to cam in the code.
But I cant find Canvas.Rendermode, og canvas.rendermode.‘something’.
private Camera cam;
// Use this for initialization
void Start ()
{
Canvas canvas = gameObject.GetComponent<Canvas>() ?? null;
cam = GameObject.FindGameObjectWithTag("GuiCamera").camera;
if(canvas != null)
{
// Set canvas' renderCamera to cam
}
else print ("derp!");
}
i dont know if you need to do the first or not. If you already have set the canvas in the inspector to “Screen Space - Camera” then you shouldnt need to.