- Home /
Changing the Canvas RenderCamera by C# script ?
Hello, I'm using Unity 4.6 with a debug UI which is rendered in a UI Canvas configured with a screen space Camera. I've associated it to a Camera1 GameObject into the Unity Editor. I would like to associate it to another camera (camera2 GameObject) by script while I'm in real time. How can I do that ? Note that I'm using Unity Free.
Regards.
Not tried this so not putting it as an answer but the only thing under Canvas that I can see is worldCamera, try setting it with that.
Easiest way to debug until you get the code syntax right would be set 2 public camera variables Cam1 and Cam2. and a public Canvas $$anonymous$$yCanvas
Drag the two cameras you want to use and the Canvas then set it with something like this:
$$anonymous$$yCanvas.worldCamera = Cam1;
//or
$$anonymous$$yCanvas.worldCamera = Cam2;
Like I said untested code, I don't have access to Unity AT$$anonymous$$.
Your answer
Follow this Question
Related Questions
Why canvas set to Screen Space - Overlay doesn't cover entire screen 0 Answers
Looking for picture in picture effect using Canvas Elements and Cinemachine follow target 0 Answers
I cannot see button on camera preview 1 Answer
My unity image isn't showing up, what gives? 0 Answers
Is there a way to make a Texture2D screenshot that ignores the canvas? 3 Answers