Warface
Warface

Reputation: 5119

How to change the Canvas Render Camera via C#

I have two camera. One which is the main camera and another that follow an object.

The main camera is attached to a canvas with HUD and other GUI Text stuff. When I change the camera to the object that need to be followed, I loose the canvas. I clearly need to change the Render Camera inside the Canvas component.

enter image description here

I've tought that something like this would exist

canvas.GetComponent<Canvas>().renderCamera...

but it's not. So how can I change the render camera via script?

Upvotes: 2

Views: 8690

Answers (2)

Gavin Thornton
Gavin Thornton

Reputation: 1897

Assign to the Canvas.worldCamera

Doesn't make sense but that's the way it is!

Upvotes: 1

I think it's this one:

https://docs.unity3d.com/ScriptReference/Canvas-worldCamera.html

canvas.worldCamera = someOtherCamera;

Upvotes: 2

Related Questions