Add a camera dynamically?

Hi,

I’m trying to create a camera dynamically using:

var cam = new camera();

But how do I add it to the scene?

there is no such thing as a camera object in a scene.
There are only gameobjects, to which you attach components, like a Camera component for example :slight_smile:

as such to add one dynamically pure code, you first need to create a game object, then add a camera component to that go

It’s probably easier if you just instantiate a camera prefab.

–Eric

Thanks, what’s the code for adding a camera to a game object?

gameObject.AddComponent (“Camera”);

Even, you can copy one camera to another or copy the setup etc. If you have different setup for different camera then create prefab of each and instantiate on necessity.