x


How do I create a Camera and make it mainCamera with csharp script ?

How do I create a Camera object in csharp script. I also want to assign it as MainCamera with tags. Currently I am getting this error :

UnassignedReferenceException: The variable levelCamera of 'StartUp' has not been assigned. You probably need to assign the levelCamera variable of the StartUp script in the inspector.

These are the two lines of code which concern the camera :

    public Camera levelCamera;

...and

       levelCamera.enabled = true;
more ▼

asked Oct 28 '11 at 04:35 PM

maggot gravatar image

maggot
190 26 28 36

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You have not assigned a Camera. You normally would drag one in via the Inspector, but to anwser your question, you would do something like (untested):

var cam = AddComponent(Camera);
cam.tag = "mainCamera";
more ▼

answered Oct 28 '11 at 05:13 PM

DaveA gravatar image

DaveA
26.8k 153 171 257

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3130
x337
x151
x146
x89

asked: Oct 28 '11 at 04:35 PM

Seen: 968 times

Last Updated: Oct 29 '11 at 08:10 AM